cshell  if expression error

ISGDude used Ask the Experts™
When the if statement evals to false it displays the error message "if Expression syntax"
It works fine when the statement is true.

set tmp = ('grep ^$EFN EFN_list.txt`)
if ($tmp == "") goto try_again

I've found a workaround using the $status variable instead of $tmp, but I don't understand why the if statement is behaving the way it does.
I use the same statement elsewhere in the program, but not for evaluating a grep statement.

The EFN_list.txt files contain lines with the following format:
js333 bicmos_sige partNumber Comments

if $EFN is set to js333 the grep statement will return the info above.  I was trying to trap for incorrect user entry when my if statement started acting up.

Whats going on here?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Top Expert 2013


your misunderstanding is that "the if expression evaluates to false".

In case that grep doesn't find the searchstring, "tmp" will be empty, so that the expanded 'if' statements reads

if (  == "") ....

which is obviously syntactically  incorrect.

Better us 'grep -c' to get a numeric value, and test this value to be zero or nonzero.


Most Valuable Expert 2014
Top Expert 2015
I get
 Unmatched '.
set tmp = ('grep ^$EFN EFN_list.txt`)
if you meant
set tmp = ( `grep ^$EFN EFN_list.txt`)
then you should probably change
if ($tmp == "") goto try_again
if ("$tmp" == "") goto try_again


Ahh,, like the old MSDOS batch file days...
Most Valuable Expert 2013
Top Expert 2013


what people want is solutions, not explanations. O tempora, o mores!


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial