Last active
June 9, 2017 14:54
-
-
Save gzagatti/f1810c125d91db017819d8b4f04e401b to your computer and use it in GitHub Desktop.
'Testing exit values in the shell.'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
failure() { | |
return 1 | |
} | |
success() { | |
return 0 | |
} | |
success | |
RET_SUCESS=$? | |
failure | |
RET_FAILURE=$? | |
echo "Sucess " $RET_SUCESS | |
echo "Failure " $RET_FAILURE | |
echo '---' | |
echo 'truthy' | |
echo '[ $RET_SUCESS -eq 0 ] ' $([ $RET_SUCESS -eq 0 ]; echo $?) | |
echo '[ $RET_SUCESS = 0 ] ' $([ $RET_SUCESS = 0 ]; echo $?) | |
echo '---' | |
echo 'falsy' | |
echo '[ $RET_SUCESS -ne 0 ]' $([ $RET_SUCESS -ne 0 ]; echo $?) | |
echo '[ $RET_SUCESS != 0 ]' $([ $RET_SUCESS != 0 ]; echo $?) | |
echo '---' | |
echo 'truthy' | |
echo '[ $RET_FAILURE -ne 0 ]' $([ $RET_FAILURE -ne 0 ]; echo $?) | |
echo '[ $RET_FAILURE != 0 ]' $([ $RET_FAILURE != 0 ]; echo $?) | |
echo '---' | |
echo 'falsy' | |
echo '[ $RET_FAILURE -eq 0 ] ' $([ $RET_FAILURE -eq 0 ]; echo $?) | |
echo '[ $RET_FAILURE = 0 ] ' $([ $RET_FAILURE = 0 ]; echo $?) | |
echo '---' | |
if [ $RET_SUCESS -eq 0 ]; then | |
echo "A: This will be shown " $RET_SUCESS | |
fi | |
if [ $RET_FAILURE -eq 0 ]; then | |
echo "B: This will not be shown " $RET_FAILURE | |
fi | |
if [ $RET_SUCESS -ne 0 ]; then | |
echo "C: This will not be shown " $RET_SUCESS | |
fi | |
if [ $RET_FAILURE -ne 0 ]; then | |
echo "D: This will be shown " $RET_FAILURE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment