From owner-freebsd-hackers@FreeBSD.ORG Sun Jun 26 09:00:27 2005 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1D8FF16A41C for ; Sun, 26 Jun 2005 09:00:27 +0000 (GMT) (envelope-from vd@datamax.bg) Received: from jengal.datamax.bg (jengal.datamax.bg [82.103.104.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id CA51E43D49 for ; Sun, 26 Jun 2005 09:00:26 +0000 (GMT) (envelope-from vd@datamax.bg) Received: from sinanica.bg.datamax (sinanica.bg.datamax [192.168.10.1]) by jengal.datamax.bg (Postfix) with QMQP id CA33687CA for ; Sun, 26 Jun 2005 12:00:25 +0300 (EEST) Received: (nullmailer pid 77923 invoked by uid 1004); Sun, 26 Jun 2005 09:00:25 -0000 Date: Sun, 26 Jun 2005 12:00:25 +0300 From: Vasil Dimov To: hackers@freebsd.org Message-ID: <20050626090025.GA77882@sinanica.bg.datamax> References: <20050626082702.GA76984@sinanica.bg.datamax> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-action=pgp-signed Content-Disposition: inline In-Reply-To: <20050626082702.GA76984@sinanica.bg.datamax> X-OS: FreeBSD 5.4-STABLE User-Agent: Mutt/1.5.9i Cc: Subject: Re: /bin/sh -e function parsing strangeness X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: vd@datamax.bg List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Jun 2005 09:00:27 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sun, Jun 26, 2005 at 11:27:02AM +0300, Vasil Dimov wrote: > > Can anyone explain this: > > % sh -ec 'f() { return 5 ; } ; if f ; then echo tt ; else echo ff ; fi' > ff > % sh -ec 'f() { return 5 ; : ; } ; if f ; then echo tt ; else echo ff ; fi' > % echo $? > 5 > > If any commands appear after the return statement in a function, > then -e flag triggers untested command failure although function call is > tested with `if' statement. > I see, -e counts for each command inside function body, no matter that the whole function return status is tested with `if'. % sh -ec 'f() { ls /nonexistent ; ls / ; } ; if f ; then echo tt ; else echo ff ; fi' ls: /nonexistent: No such file or directory % Probably this should be considered as a sh "feature". -----BEGIN PGP SIGNATURE----- iD8DBQFCvm6pFw6SP/bBpCARAu6FAKCCoGXwounURHk6o4m8huqEDtmX9wCfXqxf M0BT7Ej0fG9Iulgr/A18MMk= =/5jF -----END PGP SIGNATURE-----