[Top][All Lists]

[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: Wed, 07 May 2014 16:36:07 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

On 5/7/14, 11:43 AM, Dan Douglas wrote:
> On Wednesday, May 07, 2014 10:04:11 AM Chet Ramey wrote:
>> On 5/7/14, 2:10 AM, Dan Douglas wrote:
>>> By "doesn't shadow" you mean that it _does_ hide the global right? 
>>> Localizing
>>> a variable should cover up globals and variables in parent scopes even if 
>>> they
>>> aren't given a value. That seems true in bash 4.3 and nearly every shell
>>> (except dash).
>> I mean that a local variable that has not been given a value, and is
>> technically unset, should not shadow a global variable with the same
>> name.  Run the following script, after accounting for the local/typeset
>> differences between shells.  The results are less conclusive than you think.
> Ah ok I thought you meant the opposite. So not the "dash effect" where
> the value of a global is always still visible until a local gets a
> value.

No, that's what I'm talking about.  The local is unset until it gets a
value, so the global is still visible (not shadowed).

This is not what bash-4.3 does, but I was thinking about experimenting
with a change to make bash-4.3 behave like ksh93 and dash.  I put some
code in so I can call different functions in the `find_variable' family
to get different behavior, so I will experiement that way.

> Yes I see the results are all over the place. Basically what the big
> script linked in my previous post attempted to test, though ksh lexical
> scope makes comparison hard and not so meaningful. Your bash 4.3 way
> makes sense to me (leaving the global in the environment but shadowing
> the local).

It makes sense if you know the internals and what's going on, but it's
kind of difficult to explain.

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

reply via email to

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