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

next in thread | previous in thread | raw e-mail | index | archive | help
On 11/06/2014 12:30, Fabian Keil wrote:
> 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".

Fair enough.  What about errexit?  The shell ran a command whose exit
status was not tested, that status was failure, yet the shell did not exit.

Eric



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