Path: utzoo!utgpu!water!watmath!clyde!rutgers!princeton!udel!gatech!hao!ames!sri-spam!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.unix.questions Subject: Re: csh, exit, &&, || (was Re: exit(-1), 0 is sometimes magic) Summary: an object lesson Keywords: exit, zero, shells Message-ID: <574@cresswell.quintus.UUCP> Date: 25 Jan 88 04:32:54 GMT References: <502@cresswell.quintus.UUCP> <6935@brl-smoke.ARPA> <1179@wjvax.UUCP> <10318@mimsy.UUCP> Organization: Quintus Computer Systems, Mountain View, CA Lines: 25 > In article <310@fig.bbn.com> rsalz@bbn.com (Rich Salz) writes: > >The use of && and || in csh is the opposite of that in /bin/sh. > > /bin/sh -c "/bin/test -d foo || mkdir foo" > >Means if the foo directory doesn't exist, make it. ... > > /bin/csh -c "/bin/test -d foo || mkdir foo" > >will never make the directory, or mkdir will spit if it already exists. In every release of SunOS I've used, this does actually work. The problem is that the C-shell has TWO operators spelled "&&" and TWO operators spelled "||". The C-shell distinguishes between commands and expressions. command_1 && command_2 means execute command_1, and if it exits ZERO, execute command_2. command_1 || command_2 means execute command_1, and if it exits NON-ZERO, execute command_2. But in *expressions*, && and || have the same meaning as in C. Which is the direct opposite of their interpretation with commands! Which is just one of the reasons why I refuse to use the C-shell for writing scripts. The moral of this for C is that doing this sort of thing to operators is more trouble than it's worth. For example, the &&& and ||| operators which were proposed recently would not be a good idea.