0

The variable existence and empty values can be checked in separate if-conditions in csh.

if (! $?theVar) then

or

if ($theVar == "") then

I would like to check these conditions in a single condition. Tried something like

if ((! $?theVar) || ($theVar == "")) then

But it is not working as expected. It seems to be simple and I couldn't find a similar question. Please feel free to point it, if the question already exists.

Note: Can't change the shell. Need solution in csh only.

srand9
  • 337
  • 1
  • 6
  • 20
  • This is difficult because of csh's ad-hoc parser which doesn't really follow normal rules as in other language, it's *extremely* sensitive to spaces (`if (! $?theVar || $theVar == "" )` kinda works), and it also doesn't follow normal evaluation (it won't work if `theVar` is undefined because the part after the `||` also gets evaluated). I'd just keep the two `if`s; there's no way to get around writing ugly code if you're working with csh :-) – Martin Tournoij Aug 10 '20 at 07:03

1 Answers1

1

Even if "||" is considered to be a short-circuit operator, CSH will still syntax-check the whole thing. hence causing you the trouble. Check here and here

Try this if ((! $?theVar) && set theVar = "") || ($theVar == "")) then

Darshan K N
  • 113
  • 8