Created
October 11, 2013 14:10
-
-
Save zipizap/6935276 to your computer and use it in GitHub Desktop.
Bash ternary-like comparisons
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
# 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