bug-bash
[Top][All Lists]
Advanced

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

Re: Global variable modification by nameref chain


From: Dan Douglas
Subject: Re: Global variable modification by nameref chain
Date: Fri, 6 May 2016 09:22:07 -0500

On Fri, May 6, 2016 at 8:28 AM, Grisha Levit <grishalevit@gmail.com> wrote:
> The issue I was trying to raise is that assignment modifies the global
> variable but expansion uses the local value.
> If the assignment to the global variable is intentional, then shouldn't
> expansion use the global variable's value as well?

Nope. There's no workaround other than to unset every variable with a
conflicting name that lies between you and the global. Even if you
want to try that, there's no way to know how many such variables there
are and which one is currently visible.

declare -g is still sometimes useful though. I use it to set bash
special variables and configurations in bashrc to better ensure
they're being put into the actual global scope and should apply
everywhere. `declare -gn` is a little unusual since normally you
wouldn't use -n with other options, but I can see the use for `-gn`.



reply via email to

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