[comp.unix.internals] csh pleasures

avg@hq.demos.su (Vadim Antonov) (02/09/91)

In <10880@pasteur.Berkeley.EDU> tve@sprite.berkeley.edu (Thorsten von Eicken) writes:

>Question: what does the following c-shell script print out?
>Anybody care defending?

>	#!/bin/csh -f
>	set a=0
>	set b=1
>       if($a) then                             <<<<<< look at here. avg.
>               if($b) then                     <<<<<<
>			echo one
>		else
>			echo two
>		endif
>	else
>		echo three
>	endif

>Thorsten von Eicken - tve@sprite.berkeley.edu

It's the long lived bug in C-shell's parser - I've fixed it a couple
of years ago in the revision of C-shell for DEMOS systems.
The simpliest way to avoid this bug is to put spaces before and after ().

(After fixing this bug I still always put extra spaces - someone
could call it "a cargo-cult programming" :-).

Vadim Antonov
DEMOS, Moscow, USSR

ObBug :-)

Older versions of C-shell had && and || exchanged - to the extra fun of
novices!

guy@auspex.auspex.com (Guy Harris) (02/10/91)

>Older versions of C-shell had && and || exchanged - to the extra fun of
>novices!

And that loser version (as I remember, the bug was basically that the
author forgot that an exit status of 0 means "true" and a non-zero exit
status means "false") made it into Xenix, from what I've heard, which
prolonged its life far beyond what it should have been - that version
ended up being the C shell shipped with S5R3.2.

S5R4 has a C shell based on the SunOS 4.1 one, which is in turn based on
the 4.3BSD one, so that bug is fixed.