Created
March 1, 2022 11:54
-
-
Save stefan-vatov/9178c6346c68c9181d008afda0aef372 to your computer and use it in GitHub Desktop.
[Bash ternary] quick if-else in bash
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
# Source: https://stackoverflow.com/questions/3953645/ternary-operator-in-bash | |
[[ $b = 5 ]] && a="$c" || a="$d" | |
# or | |
a=$([ "$b" == 5 ] && echo "$c" || echo "$d") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment