diff --git a/src/condition.sh b/src/condition.sh new file mode 100644 index 0000000..94b6607 --- /dev/null +++ b/src/condition.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +equal() { + local RETURN + RETURN=0 + if [[ "$1" = "$2" ]]; + then + RETURN=1 + fi + echo $RETURN +} diff --git a/src/condition.test.sh b/src/condition.test.sh new file mode 100644 index 0000000..4e43c9f --- /dev/null +++ b/src/condition.test.sh @@ -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