Re: sh: "local" assignment from command loses exit status

From: Fabian Keil <freebsd-listen_at_fabiankeil.de>
Date: Thu, 6 Nov 2014 18:30:04 +0100
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

Received on Thu Nov 06 2014 - 16:37:01 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:53 UTC