Добавил хэлперы для if

This commit is contained in:
Sipachev Igor 2022-08-16 15:24:46 +07:00
parent f93a74941f
commit 03a637ca7a
2 changed files with 35 additions and 0 deletions

11
src/condition.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash
equal() {
local RETURN
RETURN=0
if [[ "$1" = "$2" ]];
then
RETURN=1
fi
echo $RETURN
}

24
src/condition.test.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
. ./condition.sh
# equal
if [ $(equal 1 1) -eq 1 ]
then
echo "equal numeric"
fi
if [[ $(equal 1 2) -eq 0 ]]
then
echo "not equal numeric"
fi
if [[ $(equal "asdf" "asdf") -eq 1 ]]
then
echo "equal string"
fi
if [[ $(equal "asdf" "asdf1") -eq 0 ]]
then
echo "not equal string"
fi