From owner-freebsd-questions@FreeBSD.ORG Tue Dec 27 21:36:33 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 12C7A106564A for ; Tue, 27 Dec 2011 21:36:33 +0000 (UTC) (envelope-from Devin.Teske@fisglobal.com) Received: from mx1.fisglobal.com (mx1.fisglobal.com [199.200.24.190]) by mx1.freebsd.org (Postfix) with ESMTP id CA7508FC13 for ; Tue, 27 Dec 2011 21:36:32 +0000 (UTC) Received: from pps.filterd (ltcfislmsgpa05 [127.0.0.1]) by ltcfislmsgpa05.fnfis.com (8.14.4/8.14.4) with SMTP id pBRLQW9Z026009; Tue, 27 Dec 2011 15:36:31 -0600 Received: from smtp.fisglobal.com ([10.132.206.17]) by ltcfislmsgpa05.fnfis.com with ESMTP id 11ynqqg295-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Tue, 27 Dec 2011 15:36:31 -0600 Received: from dtwin (10.14.152.15) by smtp.fisglobal.com (10.132.206.17) with Microsoft SMTP Server (TLS) id 14.1.323.3; Tue, 27 Dec 2011 15:36:30 -0600 From: Devin Teske To: "'Maxim Khitrov'" , "'FreeBSD'" References: In-Reply-To: Date: Tue, 27 Dec 2011 13:36:36 -0800 Message-ID: <029f01ccc4df$9cca8190$d65f84b0$@fisglobal.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGDxWH+b+5E3VWkBdTpf3FClEeRy5aCMvCA Content-Language: en-us X-Originating-IP: [10.14.152.15] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.5.7110, 1.0.211, 0.0.0000 definitions=2011-12-27_05:2011-12-27, 2011-12-27, 1970-01-01 signatures=0 Content-Type: text/plain; charset="utf-8" Cc: Subject: RE: Unexpected sh behavior with EXIT trap and errexit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Dec 2011 21:36:33 -0000 > -----Original Message----- > From: owner-freebsd-questions@freebsd.org [mailto:owner-freebsd- > questions@freebsd.org] On Behalf Of Maxim Khitrov > Sent: Tuesday, December 27, 2011 12:25 PM > To: FreeBSD > Subject: Unexpected sh behavior with EXIT trap and errexit >=20 > Can anyone explain this behavior (FreeBSD 9.0-RC3 amd64): >=20 > Script: > ---- > #!/bin/sh >=20 > cleanup() > { > echo 'first' > echo 'second' > } >=20 > fail() { return 42; } >=20 > trap cleanup EXIT > set -o errexit > fail > ---- >=20 > Output: > ---- > first > ---- >=20 If you change to: fail() { false; } Then the outcome is what you expect (both lines come out). ASIDE: It appears that it's nothing to do with echo, stdout, or anything ot= her than the fact that only the first command of the cleanup routine is cal= led. >From sh(1) regarding errexit: "If a shell function is executed and its exit status is explicitly tested, = all commands of the function are considered to be tested as well." The exact meaning of which escapes me at the moment, but I'm lead to believ= e that this explanation somehow plays a role in what we're witnessing with = your sample. It may be a bug, it may not. What's interesting in the sample is that the "= return 42" is a valid command that succeeds while the function itself does = not. HTH, Devin > Now comment out 'set -o errexit', replace 'fail' with 'fail || exit' > (which should be equivalent to using errexit), and run again. >=20 > Output: > ---- > first > second > ---- >=20 > Am I doing something stupid or is this a bug? Bash prints out the same > (second) output for both versions of the code. >=20 > - Max > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" _____________ The information contained in this message is proprietary and/or confidentia= l. If you are not the intended recipient, please: (i) delete the message an= d all copies; (ii) do not disclose, distribute or use the message in any ma= nner; and (iii) notify the sender immediately. In addition, please be aware= that any message addressed to our domain is subject to archiving and revie= w by persons other than the intended recipient. Thank you.