How to compare shell script?
Or, why does the following script not print anything?
x=1 if[ $x = 1 ] then echo "ok" else echo "no" fi
With numbers, use -eq , -ne , ... for equals, not equals, ...
-eq
-ne
x=1 if [ $x -eq 1 ] then echo "ok" else echo "no" fi
And for others, use == not = .
==
=
Short solution with AND and OR labels:
x=1 (( $x == 1 )) && echo "ok" || echo "no"
It depends on the language. With bash, you can use the == operator. Otherwise, you can use -eq -lt -gt for equal, lower, more than.
-lt
-gt
$ x=1 $ if [ "$x" == "2" ]; then echo "yes"; else echo "no"; fi no
Edit: Added spaces arround == and tested with 2.