Shell – arithmetic syntax error in string compare

shellshell-scripttest

I have written a shell script which takes file name as parameter e.g user/test.txt. I want to make this file parameter optional if user does not wish to provide file name he/she can give as "None"

Inside script I'm just checking if filename parameter contains "None"

if [ $filename -eq "NONE" ];then
cmd;
fi

When "None" is passed as parameter script works fine but when user/test.txt is passed I get below error message which I don't want to print on console

arithmetic syntax error

Can somebody help ?

Best Answer

[ bla bla bla ] is equivalent to test bla bla bla.

From man test

   STRING1 = STRING2
          the strings are equal

   STRING1 != STRING2
          the strings are not equal

   INTEGER1 -eq INTEGER2
          INTEGER1 is equal to INTEGER2

Therefore you need = not -eq.

Related Question