sh: "local" assignment from command loses exit status

Fabian Keil freebsd-listen at fabiankeil.de
Thu Nov 6 17:37:01 UTC 2014


Eric van Gyzen <eric at vangyzen.net> wrote:

> In sh, if I use a single statement to declare a local variable and
> assign the output of a command to it, the exit status of that command is
> lost.  For example:
> 
>     should_return_false() {
>         local var1=`false`
>     }
> 
> The function should return non-zero, but it returns zero.

The function should return the return code of the last command.
In your example, the last command is "local".

Fabian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-current/attachments/20141106/7839e66f/attachment.sig>


More information about the freebsd-current mailing list