help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to unset a local variable to expose the correspondin


From: Peng Yu
Subject: Re: [Help-bash] How to unset a local variable to expose the corresponding global variable in the function?
Date: Mon, 8 Aug 2016 07:39:09 -0500

On Mon, Aug 8, 2016 at 7:25 AM, Greg Wooledge <address@hidden> wrote:
> On Sat, Aug 06, 2016 at 09:05:12PM -0500, Peng Yu wrote:
>> Hi, The following example shows that once the variable tmp is set
>> local in a function my_fun, the function can not access the
>> corresponding global variable. Is there a way to still get the global
>> variable as if the local variable has not been set at all?
>
> No.  Stop shadowing globals that you want to access with locals of the
> same name.

That means that the author of the function needs to know what is the
global environment in which the function is called, which makes the
function not self-contained. This does not seem to be a good design
practice.

-- 
Regards,
Peng



reply via email to

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