-1

I need to compare a to z.

if[$a -eq $z]
then echo "something"
else echo "nothing"
fi

What is wrong with this code?

bwnuk
  • 69
  • 1
  • 1
  • 11

1 Answers1

1

You need spaces to separate [ from the if command, and to separate it from its arguments.

if [ "$a" -eq "$z" ]

Note also that -eq is for comparing numeric values. If the variables contain strings, you should use =.

Barmar
  • 741,623
  • 53
  • 500
  • 612