Path: utzoo!attcan!uunet!husc6!mailrus!ncar!tank!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: -e flag (Was: shell &&, || constructs) Keywords: exit status Message-ID: <13820@mimsy.UUCP> Date: 3 Oct 88 06:36:37 GMT References: <5651@sgistl.SGI.COM> <3741@boulder.Colorado.EDU> <703@necis.UUCP> <827@philmds.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 45 >In article <13810@mimsy.UUCP> I noted: >>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 article <827@philmds.UUCP> leo@philmds.UUCP (Leo de Wit) writes: >But this is according to the spec: exit *IMMEDIATELY* if a command fails. Well, yes, it *does* match the specification (in a twisted sort of way). It is merely useless. (We wanted to *test* something!) >However I agree the fix perhaps makes more sense. Maybe we need a new >metacharacter (another one!) to indicate "ignore this command's exit >status with regard to -e"; compare with make's - . Just use (set +e; cmd). (More on this in a moment.) >Playing around with -e revealed some funny things: > >After a set -e, $- contains not only e but also s: > >$ echo $- > >$ set -e >$ echo $- >se The `-s' option means `reading stdin'; it gets set automatically *after* the shell sets up $-. When you `set ', sh updates its list of currently set flags, and -s suddenly appears. I regard this as a minor bug, which I may fix later. >After a set +e, an e flag in $- is not discarded; it seems to be treated >as setting a positional parameter ... +e doesn't seem to work on my system. >This happened with /bin/sh under Ultrix 2.0. Any comments? I must have been living in an alternate universe for the last few years :-) . `set +opt' fails in the 4BSD `/bin/sh'es. The odd thing is that I remember using it, and remember it working. . . . At any rate, `set +opt' is a SysV (SysIII?) addition. It is present in recent SunOS releases. With any luck it will also be in 4.4BSD. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris