In shell scripts, I use the ternary operator as follows:
(( numVar == numVal ? (resVar=1) : (resVar=0) ))
I watched a shell script tutorial from Derek Banas and got the above syntax at 41:00 video
https://www.youtube.com/watch?v=hwrnmQumtPw&t=73s
The above code works when we assign numbers resVar
, but if I try to assign a string resVar
, it always returns 0.
(( numVar == numVal ? (resVar="Yop") : (resVar="Nop") ))
and also tried
resVar=$(( numVar == numVal ? (echo "Yop") : (echo "Nop") ))
So what is the right way to do this?
source
share