bug-bash
[Top][All Lists]
Advanced

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

Re: "local -g" declaration references local var in enclosing scope


From: Greg Wooledge
Subject: Re: "local -g" declaration references local var in enclosing scope
Date: Sun, 10 Mar 2024 18:53:09 -0400

On Sun, Mar 10, 2024 at 06:39:19PM -0400, Lawrence Velázquez wrote:
> On Sun, Mar 10, 2024, at 5:36 PM, Greg Wooledge wrote:
> > Here it is in action.  "local -g" (or "declare -g") without an assignment
> > in the same command definitely does things.
> >
> > hobbit:~$ f() { declare -g var; var=in_f; }
> > hobbit:~$ unset -v var; f; declare -p var
> > declare -- var="in_f"
> 
> This example appears to work the same without "declare -g":
> 
>       $ f() { var=in_f; }
>       $ unset -v var; f; declare -p var
>       declare -- var="in_f"

The impetus for adding it was that you *have* to declare associative
arrays.  If you want to create a global associative array from within a
function, you need the -g option.

For regular variables, it's mostly redundant, yes.



reply via email to

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