From owner-freebsd-bugs@FreeBSD.ORG Thu Feb 3 15:50:22 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C84B016A500 for ; Thu, 3 Feb 2005 15:50:22 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 83FC743D55 for ; Thu, 3 Feb 2005 15:50:16 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.1/8.13.1) with ESMTP id j13FoGPe087347 for ; Thu, 3 Feb 2005 15:50:16 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.1/8.13.1/Submit) id j13FoGLK087346; Thu, 3 Feb 2005 15:50:16 GMT (envelope-from gnats) Resent-Date: Thu, 3 Feb 2005 15:50:16 GMT Resent-Message-Id: <200502031550.j13FoGLK087346@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Brian Candler Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5FA0E16A4CE for ; Thu, 3 Feb 2005 15:41:14 +0000 (GMT) Received: from orb.pobox.com (orb.pobox.com [207.8.226.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id 59AC943D53 for ; Thu, 3 Feb 2005 15:41:12 +0000 (GMT) (envelope-from b.candler@pobox.com) Received: from orb (localhost [127.0.0.1]) by orb.pobox.com (Postfix) with ESMTP id 4A9F38F for ; Thu, 3 Feb 2005 10:41:11 -0500 (EST) Received: from billdog.local.linnet.org (dsl-80-44-135-135.access.as9105.com [80.44.135.135]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by orb.sasl.smtp.pobox.com (Postfix) with ESMTP id 1A99C8A for ; Thu, 3 Feb 2005 10:41:11 -0500 (EST) Received: from brian by billdog.local.linnet.org with local (Exim 4.43 (FreeBSD)) id 1Cwj8F-0000MS-TP for FreeBSD-gnats-submit@freebsd.org; Thu, 03 Feb 2005 15:42:59 +0000 Message-Id: Date: Thu, 03 Feb 2005 15:42:59 +0000 From: Brian Candler To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/77067: /bin/sh premature termination when 'set -e' is active X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Brian Candler List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Feb 2005 15:50:23 -0000 >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: