From owner-freebsd-bugs@FreeBSD.ORG Mon Sep 14 10:40:05 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E0F5F1065670 for ; Mon, 14 Sep 2009 10:40:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id D05208FC16 for ; Mon, 14 Sep 2009 10:40:05 +0000 (UTC) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n8EAe5hP041912 for ; Mon, 14 Sep 2009 10:40:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n8EAe5AD041911; Mon, 14 Sep 2009 10:40:05 GMT (envelope-from gnats) Date: Mon, 14 Sep 2009 10:40:05 GMT Message-Id: <200909141040.n8EAe5AD041911@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: "Alexander Melkov" Cc: Subject: Re: bin/111343: sh(1) and bash(1) with -e sometimes fail to testerrors in functions X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Alexander Melkov List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Sep 2009 10:40:06 -0000 The following reply was made to PR bin/111343; it has been noted by GNATS. From: "Alexander Melkov" To: "Jilles Tjoelker" , Cc: Subject: Re: bin/111343: sh(1) and bash(1) with -e sometimes fail to testerrors in functions Date: Mon, 14 Sep 2009 14:18:06 +0400 > Replacing the function call with the function definition, the behaviour > seems reasonable. Ok, thanks. The problem is much worse then. ==> test1.sh <== set -e { false; echo ok; } || echo failed if ! { false; echo ok; } ; then echo failed fi if ! ( false; echo ok; ) ; then echo failed fi - outputs ok ok ok > The command is tested, so -e should not trigger. Why testing the command should change the operation *within* that command? That's well beyond traditional programming, thus obviously a bug. > In general, set -e is not a good idea for more complicated scripts > because its rules can be confusing and inconsistent across shells. You > can achieve a similar effect by putting '|| exit' after commands. Ok, very nice. I'll just take my 10000 lines of scripts and add 10000 times '|| exit'. Actually -e is well defined and operates reliably except the case mentioned in this PR.