Skip site navigation (1)Skip section navigation (2)
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è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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4ad871310907191332r2f933a33l36c121903bc0742f>