[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about the return value of 'local'
From: |
Francis Moreau |
Subject: |
Re: Question about the return value of 'local' |
Date: |
Thu, 13 Dec 2012 09:54:39 +0100 |
On Thu, Dec 13, 2012 at 9:44 AM, Bob Proulx <bob@proulx.com> wrote:
> Francis Moreau wrote:
>> I found that the return value of 'local' keyword is counter intuitive
>> when the value of the assignment is an expression returning false. In
>> that case the return value of local is still true. For example:
>>
>> local foo=$(echo bar; false)
>>
>> returns true
>
> Yes. The creation of the local variable foo was successful.
>
>> whereas:
>>
>> foo=$(echo bar; false)
>>
>> returns false, that is removing the 'local' keyword has the opposite
>> behaviour.
>
> The "local" function itself is either there or it isn't. If it is
> there then the return value is the return from local. If it isn't
> there then it isn't there and the return value is of whatever you are
> checking.
>
> If the local value is there then you may use it to assign multiple
> values. How does your thinking change when thinking about having
> multiple values to local?
>
> local v1=true v2=false v3="green" v4=42
>
> If the entire operation is successful then it returns 0. If any of
> the operands fail then it returns non-zero.
Ok I see, thanks.
>
>> The help of 'local' is rather obscure about the description on its return
>> value:
>>
>> Returns success unless an invalid option is supplied, an
>> error occurs, or the shell is not executing a function.
>>
>> "an error occurs" is rather meaningless IMHO.
>>
>> Could anybody explain me why 'local' returns true in this case ?
>
> It returns 0 because the local variable was successfully created.
>
>> Also I tried to find in the documentation, where the specification of
>> the return value of an asignment is but have failed. Could anybody
>> point me out the location ?
>
> The bash manual contains this:
>
> local [option] [name[=value] ...]
Actually I was asking for the case when 'local' is not used:
foo=$(echo bar; false)
this assignment expression returns false, and I'm wondering where
that's documented.
Thanks.
--
Francis
- Question about the return value of 'local', Francis Moreau, 2012/12/13
- Re: Question about the return value of 'local', Andreas Schwab, 2012/12/13
- Re: Question about the return value of 'local', Francis Moreau, 2012/12/13
- Re: Question about the return value of 'local', Chet Ramey, 2012/12/13
- Re: Question about the return value of 'local', Francis Moreau, 2012/12/14
- Re: Question about the return value of 'local', Greg Wooledge, 2012/12/14
- Re: Question about the return value of 'local', Francis Moreau, 2012/12/14
- Re: Question about the return value of 'local', Chet Ramey, 2012/12/14
- Re: Question about the return value of 'local', Chet Ramey, 2012/12/14