csh problem involving nested ifs?

David C Lawrence tale at pawl.rpi.edu
Tue Jul 11 03:11:39 AEST 1989


In <685 at wuphys.UUCP> marty at wuphys.UUCP (Marty Olevitch) writes:
Marty> It appears that csh does not correctly handle nested if-then-else
Marty> statements. The following script illustrates the problem, which appears
Marty> in versions of csh on MORE/bsd (mt Xinu 4.3), SunOS 3.1, SunOS 4.0, and
Marty> Ultrix 2.0. Am I missing some bug in this script? If not, it looks like
Marty> a bug in csh (an equivalent sh program works fine).

Yes it's a bug, no it's not a bug.  It's one of those ambivalent
things.  If you know what it is, you adjust your style by one
character or so and life goes on correctly again.

Major hacking on the script follows ...
Marty> #! /bin/csh
[...]
Marty> if($v1 == 1) then
Marty> 	echo checkpoint 1
Marty> 	if($v2 == 1) then
[...]
Marty> 	if($v2 == 1) then
[...]

If you change the "if(" to "if (" in each of the nested conditionals
you should find that your problem has vanished.  The problem is that
whitespace becomes significant within the first if block, at least as
far as further nested if blocks are concerned.  The parser used within
the if block is not the same one which parsed out the top if.

Dave
--
 (setq mail '("tale at pawl.rpi.edu" "tale at itsgw.rpi.edu" "tale at rpitsmts.bitnet"))
        "Drinking coffee for instant relaxation?  That's like drinking
               alcohol for instant motor skills."  -- Marc Price



More information about the Comp.bugs.4bsd.ucb-fixes mailing list