I am writing a script under Unix system.
Is there any way to assign value like this:
x=($1 == "") ? 3 : 4
if $1
is empty we will assign value "3" to x, otherwise the value "4"
I am writing a script under Unix system.
Is there any way to assign value like this:
x=($1 == "") ? 3 : 4
if $1
is empty we will assign value "3" to x, otherwise the value "4"
You can do it with either let
or (())
bash constructions. For example:
a=1
let "b = a == 1 ? 2 : 3"
echo $b
For further details see man 1 bash