Ioctl Errors
Chuck Privitera
crp at ccivax.UUCP
Wed Jun 13 02:47:02 AEST 1984
I have seen some very bizarre things happen in C-shell scripts due
to a bug in parsing if statements. In the manual it outlines the
syntax of if to be:
if(expr) command
or
if(expr) then
...
else if(expr2) then
...
else
...
endif
Notice that the example shows no space between the if and the
opening paren. Now, in C, bc, awk, etc., a space between if
and the opening paren is optional, in the C-shell, if you don't
have a space there nested ifs break. Here is an example that shows
the problem:
#!/bin/csh -f
if ( $?a ) then
echo the variable a is set
if( $?b ) then
echo the variable b is set
else if ( $?c ) then
echo the variable c is set
else
echo a is set but b nor c are.
endif
else
echo a is not even set
endif
If you run this without setting a variable a or b or c, the
output will be "a is set but b nor c are." . The first if is
matching the first else! The problem is that the second if,
i.e. if( $?b ), needs a space between if and the left paren.
Obvious isn't it!!! I haven't bothered to chase the problem
down I don't usually write shell scripts in C-shell. I think
I first ran into this in my .cshrc file. Anyways, C-shell
programmers beware this one.
Chuck Privitera, Computer Consoles Inc.
{allegra,seismo}!rochester!ritcv!ccivax!crp
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list