Date: Sun, 19 Jul 2009 16:32:28 -0400 From: Glen Barber <glen.j.barber@gmail.com> To: =?ISO-8859-1?Q?Romain_Tarti=E8re?= <romain@blogreen.org> Cc: stable@freebsd.org Subject: Re: Value of $? lost in the beginning of a function. Message-ID: <4ad871310907191332r2f933a33l36c121903bc0742f@mail.gmail.com> In-Reply-To: <20090719202638.GA85228@blogreen.org> References: <20090719202638.GA85228@blogreen.org>
next in thread | previous in thread | raw e-mail | index | archive | help
2009/7/19 Romain Tarti=E8re <romain@blogreen.org>: > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4ad871310907191332r2f933a33l36c121903bc0742f>