Created
November 14, 2023 21:49
-
-
Save iTrooz/b793771a190c50260030f49814d97be2 to your computer and use it in GitHub Desktop.
bash_conditions
This file contains hidden or 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
# Everything here prints "OK" | |
# 1 is true | |
if (( 1 )); then | |
echo "OK" | |
else | |
echo "NOT OK" | |
exit 1 | |
fi | |
# "1" is true | |
if (( "1" )); then | |
echo "OK" | |
else | |
echo "NOT OK" | |
exit 1 | |
fi | |
# 0 is false | |
if (( 0 )); then | |
echo "NOT OK" | |
exit 1 | |
else | |
echo "OK" | |
fi | |
# "0" is false | |
if (( "0" )); then | |
echo "NOT OK" | |
exit 1 | |
else | |
echo "OK" | |
fi | |
# An unset string is false | |
if (( "" )); then | |
echo "NOT OK" | |
exit 1 | |
else | |
echo "OK" | |
fi | |
# Another string is **false** | |
if (( "true" )); then | |
echo "NOT OK" | |
exit 1 | |
else | |
echo "OK" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment