Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Nov 2014 18:30:04 +0100
From:      Fabian Keil <freebsd-listen@fabiankeil.de>
To:        Eric van Gyzen <eric@vangyzen.net>
Cc:        Freebsd current <freebsd-current@freebsd.org>
Subject:   Re: sh: "local" assignment from command loses exit status
Message-ID:  <74dd7d12.793ea654@fabiankeil.de>
In-Reply-To: <545BADDE.5050605@vangyzen.net>
References:  <545BADDE.5050605@vangyzen.net>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
Eric van Gyzen <eric@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

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlRbsBwACgkQBYqIVf93VJ2HogCfTGoqZbQ5MjzNxEBm07OEdWe6
LqQAn2KZOeKJPUcZ2JAW1cQQVPCK6IX6
=mvfS
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?74dd7d12.793ea654>