bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Return status of command substitution with $(...) "gets lost"


From: Eric Blake
Subject: Re: Return status of command substitution with $(...) "gets lost"
Date: Wed, 10 Mar 2010 10:41:25 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100301 Fedora/3.0.3-1.fc12 Lightning/1.0b1 Thunderbird/3.0.3

On 03/10/2010 10:28 AM, Marc Herbert wrote:
> Chet Ramey a écrit :
>> On 3/4/10 2:36 AM, Ettelbrueck, Heiko wrote:
>>>         Problem: The $? variable is always 0 after that statement. (If,
>>>         on the other hand, I separate the declaration and the
>>>         definition of the variable as shown in the example below, the
>>>         $? variable is really set to the exit status of the external
>>>         tool.)
>>
>> The exit status is the status of the command you run: local.  In the
>> absence of a command, when there are only assignment statements, the
>> exit status can be the exit status of a command substitution:
> 
> I have been bitten by this a few times. Since then I never, ever write this:
>   local foo=...
> 
> But always:
>   local foo; foo=...

On the other hand, local is not specified by POSIX.  What would it hurt
to redefine the exit status of local to reflect the status of any
command substitutions performed during the local assignments (short of
compatibility with zsh)?

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]