Skip to content

Instantly share code, notes, and snippets.

@stefan-vatov
Created March 1, 2022 11:54
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 stefan-vatov/9178c6346c68c9181d008afda0aef372 to your computer and use it in GitHub Desktop.
Save stefan-vatov/9178c6346c68c9181d008afda0aef372 to your computer and use it in GitHub Desktop.
[Bash ternary] quick if-else in bash
# 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