Is there a way to do something like this using Bash?
int a = (b == 5) ? c : d;Thanks.
Is there a way to do something like this using Bash?
int a = (b == 5) ? c : d;Thanks.
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"
[ $b == 5 ] && a=$c || a=$d
But watch out with this construct, as the part after the || is also executed when the part between && and || fails.
(ping -c1 localhost&>/dev/null) && { echo "true"; } || {  echo "false"; }