On 09/22/2015 08:19 AM, idal...@idallen-fibe.dyndns.org wrote:
> Description:
>       Adding a "local" keyword to a variable assignment hides the
>       return code of a command substitution.  Same problem in both
>       bash and dash shells.
> 

Not a bug.

$() substition can only affect $? if it is executed in isolation, and
not as an argument to some other command.  'local' is some other command.

And while 'local' is not (yet) in POSIX, the behavior is the same for
'export', which IS specified by POSIX.

For more details, read:
http://austingroupbugs.net/view.php?id=960#c2777

in particular the section that says:

> Note that, unless X was previously marked readonly, the value of $? after
> 
> export X=$(false)
> 
> will be 0 (because export successfully set X to the empty string) and that 
> execution continues, even if set -e is in effect. In order to detect command 
> substitution failures, a user must separate the assignment from the export, 
> as in
> 
> X=$(false)
> export X

So, as you discovered,

>       The work-around is to use "local" to declare the variable first,
>       then do the command substitution assignment on another line and
>       check the return code there.

That is not a workaround, so much as the correct behavior.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to