From owner-freebsd-bugs Wed Mar 18 02:58:46 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id CAA10726 for freebsd-bugs-outgoing; Wed, 18 Mar 1998 02:58:46 -0800 (PST) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from dt050n33.san.rr.com (@dt050n33.san.rr.com [204.210.31.51]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id CAA10658; Wed, 18 Mar 1998 02:58:33 -0800 (PST) (envelope-from Studded@dal.net) Received: from dal.net (Studded@localhost [127.0.0.1]) by dt050n33.san.rr.com (8.8.8/8.8.8) with ESMTP id CAA04889; Wed, 18 Mar 1998 02:58:25 -0800 (PST) (envelope-from Studded@dal.net) Message-ID: <350FA8D0.A9CCF864@dal.net> Date: Wed, 18 Mar 1998 02:58:24 -0800 From: Studded Organization: Triborough Bridge & Tunnel Authority X-Mailer: Mozilla 4.04 [en] (X11; I; FreeBSD 2.2.6-BETA-0316 i386) MIME-Version: 1.0 To: Bruce Evans CC: dancy@franz.com, freebsd-bugs@FreeBSD.ORG, freebsd-gnats-submit@FreeBSD.ORG Subject: Re: bin/6047: bash does not handle -e option properly References: <199803180924.UAA32209@godzilla.zeta.org.au> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Bruce Evans wrote: > --- > #!/bin/sh > set -e > funcfalse() { > return 1 > } > > for i in /usr/bin/false false funcfalse > do > if $i; then echo $i; else echo not $i; fi > done > --- When I run this, I get: $ testpr not /usr/bin/false not false $ I'm not sure what you're getting at here, since it seems to me that what you really want to test is the value of `false` rather than the string "false," but like I said, I think I'm missing something. My understanding is that "exit codes" should be numbers, "zero for normal or success, and non-zero for failure, error, or a false indication" to quote the man page for sh. > This handles funcfalse different from the other falses. /bin/sh apparently > exits for `return 1' when -e is set. No, sh exits for the exit status of funcfalse being '1'. Return is a builtin whose only job is to terminate and report the exit status of the function. > The correctness of this for a POSIX > shhell depends on whether `return' is a simple command. I don't think it > is. This examples shows why it shouldn't be. Here is a more detailed example: #!/bin/sh set -e testtrue () { true return $? } testfalse () { false return $? } echo 'First test inside a function, we know it will work' if testtrue ; then echo 'See, it worked' fi # Run the first time with this uncommented, # then comment and run again. echo 'Second test inside a function, we should continue on after this' if testfalse; then echo 'You should not see this because the condition is false' fi echo 'First test w/o function, we know it will work' if true; then echo 'See, it worked' fi echo 'Second test w/o function, we should continue on after this' if false; then echo 'You should not see this because the condition is false' fi echo 'First untested command, we know it will work' true echo " Exit status of first test is: $? " echo 'Second untested command, we should exit after this' false echo " If you can see this, set is broken in sh" The commented section demonstrates what I think the point of contention is. The shell is handling functions differently than it is handling "commands." My initial response was based on my belief that this was the desired behaviour. You however are in a much better position to deal with the POSIX definitions of those terms than I am, so I bow to your expertise. If a "function" is not a "command," then set -e is working as advertised, if not as we'd expect. If the terms are equivalent, there is a bug. I suspect that the terms are equivalent and that my initial response was incorrect based on the fact that bash handles the whole script and doesn't exit at the false tested function. The reason I asked what the PR originator was trying to accomplish was to offer my assistance in accomplishing the actual goal (which I doubt was to test various permutations of shell settings :). The offer is still open. Doug -- *** Chief Operations Officer, DALnet IRC network *** *** Proud operator, designer and maintainer of the world's largest *** Internet Relay Chat server. 5,328 clients and still growing. *** Try spider.dal.net on ports 6662-4 (Powered by FreeBSD) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message