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: Dan Douglas
Subject: Re: 'local -x VARIABLE' does not clear variable for subprocesses
Date: Tue, 06 May 2014 23:10:03 -0700 (PDT)
User-agent: KMail/4.13 (Linux/3.14.0-pf1+; KDE/4.13.0; x86_64; ; )

On Monday, May 05, 2014 11:18:50 AM Chet Ramey wrote:
> The idea behind the bash-4.3 behavior is that the placeholder local
> variable isn't set, and doesn't really exist.  It doesn't shadow a
> global variable with the same name until it gets a value.  The bash-4.2
> behavior was inconsistent: variables with attributes but without values
> weren't quite set (value == 0x0, but still visible) and weren't quite
> unset.  I tightened up the some of the consistency starting with bash-4.3
> beta.  I'm sure there are still inconsistencies there (and, in fact, I
> found one while looking at this).

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).

If you want to set an attribute without localizing the variable then you've 
always been able to use "export" or "readonly" in place of "local -x".

I also wouldn't want this example to change so that ref always appears set. 
The localized x in g should hide f's x even with no value.

    function f { typeset x=set; g x; }
    function g { typeset x; h x; }
    function h { typeset -n ref=$1; echo "${ref-unset}"; }
    f x # should print "unset"

-- 
Dan Douglas



reply via email to

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