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? Thanks, Romain -- Romain Tarti?re <romain@blogreen.org> http://romain.blogreen.org/ pgp: 8DAB A124 0DA4 7024 F82A E748 D8E9 A33F FF56 FF43 (ID: 0xFF56FF43) (plain text =non-HTML= PGP/GPG encrypted/signed e-mail much appreciated) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/freebsd-stable/attachments/20090719/929bb0cc/attachment.pgp
2009/7/19 Romain Tarti?re <romain@blogreen.org>:> 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? >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' ? -- Glen Barber
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
On Sun, Jul 19, 2009 at 10:47:55PM +0200, Jilles Tjoelker wrote:> This has been fixed in 8.x:Cool, thanks! -- Romain Tarti?re <romain@blogreen.org> http://romain.blogreen.org/ pgp: 8DAB A124 0DA4 7024 F82A E748 D8E9 A33F FF56 FF43 (ID: 0xFF56FF43) (plain text =non-HTML= PGP/GPG encrypted/signed e-mail much appreciated) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available Url : http://lists.freebsd.org/pipermail/freebsd-stable/attachments/20090719/bfd2d134/attachment.pgp
do you plan to MFC this fix? On 7/19/09, Romain Tarti?re <romain@blogreen.org> wrote:> On Sun, Jul 19, 2009 at 10:47:55PM +0200, Jilles Tjoelker wrote: >> This has been fixed in 8.x: > Cool, thanks! > > -- > Romain Tarti?re <romain@blogreen.org> http://romain.blogreen.org/ > pgp: 8DAB A124 0DA4 7024 F82A E748 D8E9 A33F FF56 FF43 (ID: 0xFF56FF43) > (plain text =non-HTML= PGP/GPG encrypted/signed e-mail much appreciated) >