Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

    echo 1111

However it apparently does not work.

It gives this error message:

/usr/bin/test: argument expected
if: Expression Syntax.
share|improve this question
up vote 3 down vote accepted


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

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

share|improve this answer
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 1: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 9: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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .