Is there a way to do something like this
int a = (b == 5) ? c : d;
using Bash?
Bash programming does not have support for ternary operator syntax. The syntax is similar to if and else conditional expression.
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
A regular expression matching sign, the =~ operator, is used to identify regular expressions. Perl has a similar operator for regular expression corresponding, which stimulated this operator.
A ternary operator lets you assign one value to the variable if the condition is true, and another value if the condition is false. The if else block example from above could now be written as shown in the example below. var num = 4, msg = ""; msg = (num === 4) ?
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With