From owner-freebsd-stable@FreeBSD.ORG Sun Jul 19 20:32:30 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 49330106566C for ; Sun, 19 Jul 2009 20:32:30 +0000 (UTC) (envelope-from glen.j.barber@gmail.com) Received: from mail-fx0-f205.google.com (mail-fx0-f205.google.com [209.85.220.205]) by mx1.freebsd.org (Postfix) with ESMTP id CEBC28FC18 for ; Sun, 19 Jul 2009 20:32:29 +0000 (UTC) (envelope-from glen.j.barber@gmail.com) Received: by fxm1 with SMTP id 1so84975fxm.43 for ; Sun, 19 Jul 2009 13:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=1wIpA3lPEkQODfvoXOwyiHtxt27K7e3Zik9VzzX5dr0=; b=CjmMir72Q9A4n8gIeAP2/QaTg+vm97EbMmHXcOblbm1irKvgYO5Da9xZQ2HtxqR0NM VMeOKpIfd0Xh4cnmpz43M04AK0/hxApUcUAFv8GwqLqUsEpxVNRUj9Fm7iAyX20og+ky TYyQs8I8JI/wEbgkT+3utVGiYa2Y1ZaY3TYhM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=kSPNbwysHvd+4RlVdNQGgryB9OPE/cpEueWTC2IjpuJWL7PwrZpqVe/wGw8hdn9/aP XOGmfvRRK8GZi4zJA2y9Fdn5QLgijB6cB8xmQKK3ehmmudIuAHLR00l56bO7mfBGDIek SmLSCEipEV4rZVC5Fdv3YXSCA2OdlPsUb0/z4= MIME-Version: 1.0 Received: by 10.223.108.15 with SMTP id d15mr988882fap.62.1248035548801; Sun, 19 Jul 2009 13:32:28 -0700 (PDT) In-Reply-To: <20090719202638.GA85228@blogreen.org> References: <20090719202638.GA85228@blogreen.org> Date: Sun, 19 Jul 2009 16:32:28 -0400 Message-ID: <4ad871310907191332r2f933a33l36c121903bc0742f@mail.gmail.com> From: Glen Barber To: =?ISO-8859-1?Q?Romain_Tarti=E8re?= Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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:32:30 -0000 2009/7/19 Romain Tarti=E8re : > Hi! > > Simple test case: > > ----8<---------------------- > #!/bin/sh > foo() > { > =A0echo "\$?=3D$? \$1=3D$1" > } > false > foo $? > ----8<---------------------- > > % sh foo.sh > $?=3D0 $1=3D1 > % zsh foo.sh > $?=3D1 $1=3D1 > % bash foo.sh > $?=3D1 $1=3D1 > > As you can see, the value of $? is =AB lost =BB when FreeBSD sh enters a > function. =A0Is this supposed to behave this way? > Hi. I'm no expert at shell scripting, but my first presumption is that since you have '#!/bin/sh' at the beginning of the script, it is creating a new subshell, and overwriting the value. What happens if you replace '#!/bin/sh' with '#!/usr/local/bin/zsh' ? --=20 Glen Barber