Search code examples
shellsyntaxscriptingsyntax-errorcsh

CSH If: "Expression Syntax" Error for String Comparison with the value "("


I have a shell if statement as below:

if($var1!= $var2) then
    ...  
endif

when the value of string var1 is "(", I get the following error:

if: Expression Syntax

I know that ( is a syntactic character and I wonder If there is any walkaround to compare a string value for (

Thanks.


Solution

  • Use double quotes:

    if ("$var1" != "$var2") then
      ... 
    endif