4

I want to test if a variable is totally empty in csh.

set R='dddd aaa'
if ( '${R}' ) then
    echo not empty

else
    echo 1111
endif

However it apparently does not work.

It gives this error message:

/usr/bin/test: argument expected
if: Expression Syntax.
Anthony Kong
  • 4,868
  • 11
  • 48
  • 80

1 Answers1

3

Use

if ( "x$R" == "x" ) then
    echo empty
else
    echo not empty
endif

The C shell doesn't have an empty operator like bash. Also, you can't quote with ' as it will prevent the variable expansion.

e40
  • 1,318
  • 9
  • 10
  • It works. Thanks. But for some reason, the "/usr/bin/test: argument expected" error message remains. Do you know why? – Anthony Kong Sep 16 '11 at 01:15
  • You probably have a superfluous bracket somewhere else in your script (they are a shorthand for /usr/bin/test) – RedGrittyBrick Sep 16 '11 at 09:41
  • Do "set echo" at the top of the script. It's coming from somewhere else, I'm sure, because I ran the code above through csh and it didn't complain. – e40 Sep 16 '11 at 13:56