bug-bash
[Top][All Lists]
Advanced

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

Re: 'local -x VARIABLE' does not clear variable for subprocesses


From: Chet Ramey
Subject: Re: 'local -x VARIABLE' does not clear variable for subprocesses
Date: Mon, 05 May 2014 11:25:20 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

On 5/3/14, 10:59 PM, Linda Walsh wrote:
> 
> 
> Arfrever Frehtes Taifersar Arahesis wrote:
>> bash 4.2.47:
>> $ export VAR1=abc VAR2=abc
>> $ f() { local VAR1; local -x VAR2; bash -c 'declare -p VAR{1,2}'; }
>> $ f
>> bash: line 0: declare: VAR1: not found
>> bash: line 0: declare: VAR2: not found
>>
>> bash 4.3.11:
>> $ export VAR1=abc VAR2=abc
>> $ f() { local VAR1; local -x VAR2; bash -c 'declare -p VAR{1,2}'; }
>> $ f
>> declare -x VAR1="abc"
>> declare -x VAR2="abc"
> ---
>    What's especially peculiar is that if you change VAR1+VAR2
> in 'f', then the called bash in 'f' should still see the original
> value of VAR1 as it was not exported (but it sees both
> values as assigned in 'f'.

Yes.  Once you assign a value to the local instances of the variables,
they are set.

Local variables inherit the exported status of the variable they are
shadowing to avoid surprises in the export environment.  Believe it or
not, it's less surprising than letting a local variable shadow a global
for everything except exporting to child processes.  It's been that way
forever (well, at least as far back as bash-2.05b, when I quit looking.)

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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