Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uwmcsd1!marque!uunet!mcvax!cernvax!ethz!iis!prl From: prl@iis.UUCP (Peter Lamb) Newsgroups: comp.unix.questions Subject: Re: shell &&, || constructs (really /bin/sh -e behaviour) Keywords: exit status Message-ID: <639@eiger.iis.UUCP> Date: 4 Oct 88 06:14:31 GMT References: <5651@sgistl.SGI.COM> <3741@boulder.Colorado.EDU> <703@necis.UUCP> <826@philmds.UUCP> <13810@mimsy.UUCP> Reply-To: prl@iis.UUCP (Peter Lamb) Organization: Integrated Systems Lab., ETH Zuerich Lines: 34 In article <13810@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >Regarding `set -e': again, beware! Old versions of /bin/sh will >exit if the test portion of an `if', `while', or `until' returns >a nonzero status, if `-e' is set. (These are fixed in 4.3BSD-tahoe.) >In addition, `command1 || command2' will exit if command1 fails. >(It will also exit if command2 fails, but that seems sensible. >I believe SysV's /bin/sh does *not* exit if command2 fails. If >this is considered correct behaviour, let me know, because I just >`fixed' this to work the way I think seems sensible.) > >In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) >Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris And some not-so-old /bin/sh's. This is one of my pet peeves with Ultrix. Up to and including Ultrix 2.2 DEC's /bin/sh does just this, which makes makefiles using conditionals difficult to do right. DEC's /bin/sh5 (SysV shell) works correctly in this respect, but... because DEC added the { command ; command } syntax to their shell, and then put this in just about every critical shell script on the system, you can't make the SysV shell /bin/sh (or rather you can, but you won't be able to boot multi-user nor load DEC layered products :-) . And just to support Chris' case that sh -e should not exit if the command in a conditional returns non-zero status; if you have a conditional, it is usually because you *EXPECT* the thing to fail sometimes, otherwise you wouldn't have bothered! -- Peter Lamb uucp: seismo!mcvax!ethz!prl eunet: prl@ethz.uucp Tel: +411 256 5241 Institute for Integrated Systems ETH-Zentrum, 8092 Zurich