From owner-freebsd-stable@FreeBSD.ORG Sun Jul 19 20:47:56 2009 Return-Path: Delivered-To: stable@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 95D60106564A for ; Sun, 19 Jul 2009 20:47:56 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) by mx1.freebsd.org (Postfix) with ESMTP id 59E908FC1E for ; Sun, 19 Jul 2009 20:47:56 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from toad.stack.nl (toad.stack.nl [IPv6:2001:610:1108:5010::135]) by mx1.stack.nl (Postfix) with ESMTP id 68B03375B20; Sun, 19 Jul 2009 22:47:55 +0200 (CEST) Received: by toad.stack.nl (Postfix, from userid 1677) id 4FD6D73FA2; Sun, 19 Jul 2009 22:47:55 +0200 (CEST) Date: Sun, 19 Jul 2009 22:47:55 +0200 From: Jilles Tjoelker To: Romain =?iso-8859-1?Q?Tarti=E8re?= Message-ID: <20090719204755.GA94947@stack.nl> References: <20090719202638.GA85228@blogreen.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20090719202638.GA85228@blogreen.org> User-Agent: Mutt/1.5.18 (2008-05-17) Cc: stable@FreeBSD.org Subject: Re: Value of $? lost in the beginning of a function. X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jul 2009 20:47:56 -0000 On Sun, Jul 19, 2009 at 10:26:38PM +0200, Romain Tartière wrote: > Hi! > > Simple test case: > > ----8<---------------------- > #!/bin/sh > foo() > { > echo "\$?=$? \$1=$1" > } > false > foo $? > ----8<---------------------- > > % sh foo.sh > $?=0 $1=1 > % zsh foo.sh > $?=1 $1=1 > % bash foo.sh > $?=1 $1=1 > > As you can see, the value of $? is « lost » when FreeBSD sh enters a > function. Is this supposed to behave this way? This has been fixed in 8.x: Revision 185231 - Directory Listing Modified Sun Nov 23 20:23:57 2008 UTC (7 months, 3 weeks ago) by stefanf Fix $? at the first command of a function. The previous exit status was saved twice and thus lost. -- Jilles Tjoelker