Skip to content

Instantly share code, notes, and snippets.

@zipizap
Created October 11, 2013 14:10
Show Gist options
  • Save zipizap/6935276 to your computer and use it in GitHub Desktop.
Save zipizap/6935276 to your computer and use it in GitHub Desktop.
Bash ternary-like comparisons
# condition && command-if-true || command-if-false
#
# CAUTION: condition && ... || ... works, but
# condition || ... && ... does NOT work!
#
$ [[ "your" == "condition" ]] && echo "executed if true" || echo "executed if false"
executed if false
$ [[ "your" == "your" ]] && echo "executed if true" || echo "executed if false"
executed if true
# CAUTION: condition || ... && ... does NOT work!
$ [[ "your" == "your" ]] || echo "executed if false" && echo "executed if true"
executed if true
$ [[ "your" == "condition" ]] || echo "executed if false" && echo "executed if true"
executed if false
executed if true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment