It must be:
if [ $x -eq 3 ]; then .....
if you prefer a more readable and self-explanatory code, use this syntax:
if test $x -eq 3; then .....
explanation:
To compare integers you must use those operators (copied from man test):
INTEGER1 -eq INTEGER2
INTEGER1 is equal to INTEGER2
INTEGER1 -ge INTEGER2
INTEGER1 is greater than or equal to INTEGER2
INTEGER1 -gt INTEGER2
INTEGER1 is greater than INTEGER2
INTEGER1 -le INTEGER2
INTEGER1 is less than or equal to INTEGER2
INTEGER1 -lt INTEGER2
INTEGER1 is less than INTEGER2
INTEGER1 -ne INTEGER2
INTEGER1 is not equal to INTEGER2
operators == and != are for string comparison only.
for information: "[" command is an alias for system "test" command.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…