Date: Thu, 03 Feb 2005 15:42:59 +0000 From: Brian Candler <B.Candler@pobox.com> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/77067: /bin/sh premature termination when 'set -e' is active Message-ID: <E1Cwj8F-0000MS-TP@billdog.local.linnet.org> Resent-Message-ID: <200502031550.j13FoGLK087346@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 77067 >Category: bin >Synopsis: /bin/sh premature termination when 'set -e' is active >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Feb 03 15:50:16 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Brian Candler >Release: FreeBSD 5.3-STABLE i386 >Organization: >Environment: System: FreeBSD billdog.local.linnet.org 5.3-STABLE FreeBSD 5.3-STABLE #0: Mon Dec 27 12:24:34 GMT 2004 root@billdog.local.linnet.org:/usr/obj/usr/src/sys/BILLDOG i386 >Description: Under certain circumstances, 'set -e' causes /bin/sh to exit when it should not. From the manpage: -e errexit Exit immediately if any untested command fails in non-interactive mode. The exit status of a command is considered to be explic- itly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an `&&'' or `||'' operator. However, there are circumstances where even when a command status is explicitly tested the script still terminates. I can replicate this using a function call. >How-To-Repeat: This script demonstrates the problem: ------------------------------------------------------------ #!/bin/sh set -e foo ( ) { if test "x$1" != "xyes"; then return 1 fi echo "OK!" # this line causes the problem! } if foo yes; then echo "yes"; fi if foo no; then echo "no"; fi echo "Completed!" ------------------------------------------------------------ It fails to complete. However, if you remove the 'echo "OK!"' line it *does* complete. (This line can be anything - for example, replacing it with "return 0" also causes the problem). The script runs correctly under 'bash', so I don't think my understanding of -e semantics is broken. >Fix: >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1Cwj8F-0000MS-TP>