ternary operator ? :
is just short form of if/else
case "$b" in
5) a=$c ;;
*) a=$d ;;
esac
Or
[[ $b = 5 ]] && a="$c" || a="$d"
More Related Contents:
- How to concatenate string variables in Bash
- How do I iterate over a range of numbers defined by variables in Bash?
- Difference between single and double quotes in Bash
- Why should there be spaces around ‘[‘ and ‘]’ in Bash?
- Command not found error in Bash variable assignment
- Why does shell ignore quoting characters in arguments passed to it through variables? [duplicate]
- How to escape single quotes within single quoted strings
- How to use double or single brackets, parentheses, curly braces
- When do we need curly braces around shell variables?
- Brace expansion with variable? [duplicate]
- What is the benefit of using $() instead of backticks in shell scripts? [duplicate]
- Usage of :- (colon dash) in bash
- Why equal to operator does not work if it is surrounded by space?
- What is the purpose of “&&” in a shell command?
- Tilde in path doesn’t expand to home directory
- Bash syntax error: unexpected end of file
- Test for non-zero length string in Bash: [ -n “$var” ] or [ “$var” ]
- What is the meaning of the ${0##…} syntax with variable, braces and hash character in bash?
- Compound ‘if’ statements with multiple expressions in Bash
- Why source command doesn’t work with process substitution in bash 3.2?
- Using the && operator in an if statement
- bash: $[] vs. $(())
- Commenting in a Bash script inside a multiline command
- What does “plus colon” (“+:”) mean in shell script expressions?
- osascript using bash variable with a space
- bash “if [ false ];” returns true instead of false — why?
- Why equal to operator does not work if it is not surrounded by space?
- What does the curly-brace syntax ${var%.*} mean?
- Rsync syntax error when run from bash script
- What is the proper way to test a Bash function’s return value?