Another Reason Not to Write csh Scripts
In case you haven’t read Tom Christiansen’s
Csh Programming Considered Harmful,
here’s another reason not to write csh/tcsh scripts
if you can avoid it.
Unlike the Bourne Shell, the C shell exits with “Undefined variable”
if you reference an undefined variable, instead of expanding that
variable to the empty string, the way the Bourne shell and Perl do.
But there’s the $?VAR construct, which allows you to
tell whether a variable is set.
I needed to check this in a script that, for reasons I won’t go into
here, needed to be written in Csh. So I had
if ( !$?FOO ) then # Stuff to do if $FOO isn't set
and got an error. It turns out that csh started by evaluating
$?FOO. In this case, $FOO was set, so $?FOO
was set to 0. Csh then tried to evaluate !0 and parsed it as
“event number zero”, which failed. Grrr.
Putting a space between the bang and the dollar sign fixed that.