Skip to content

Instantly share code, notes, and snippets.

@iTrooz
Created November 14, 2023 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iTrooz/b793771a190c50260030f49814d97be2 to your computer and use it in GitHub Desktop.
Save iTrooz/b793771a190c50260030f49814d97be2 to your computer and use it in GitHub Desktop.
bash_conditions
# 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