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

2024-03-10 Thread Kerin Millar
On Sun, 10 Mar 2024 17:36:13 -0400 Greg Wooledge wrote: > On Sun, Mar 10, 2024 at 04:01:10PM -0400, Lawrence Velázquez wrote: > > Basically, without an assignment, "local -g" does nothing. > > Well, the original purpose of -g was to create variables, especially > associative arrays, at the globa

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

2024-03-10 Thread Kerin Millar
On Sun, 10 Mar 2024 16:01:10 -0400 Lawrence Velázquez wrote: > On Sun, Mar 10, 2024, at 1:51 PM, Kerin Millar wrote: > > Dynamic scoping can be tremendously confusing. The following examples > > should help to clarify the present state of affairs. > > > > $ x() { local a; y; echo "outer: $a"; }

nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope)

2024-03-10 Thread Zachary Santer
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: msys Compiler: gcc Compilation CFLAGS: -march=nocona -msahf -mtune=generic -O2 -pipe -D_STATIC_BUILD uname output: MINGW64_NT-10.0-19045 Zack2021HPPavilion 3.4.10.x86_64 2024-02-10 08:39 UTC x86_64 Msys Machine

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

2024-03-10 Thread Greg Wooledge
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

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

2024-03-10 Thread Lawrence Velázquez
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

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

2024-03-10 Thread Greg Wooledge
On Sun, Mar 10, 2024 at 04:01:10PM -0400, Lawrence Velázquez wrote: > Basically, without an assignment, "local -g" does nothing. Well, the original purpose of -g was to create variables, especially associative arrays, at the global scope from inside a function. I think this thread has been asking

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

2024-03-10 Thread Lawrence Velázquez
On Sun, Mar 10, 2024, at 1:51 PM, Kerin Millar wrote: > Dynamic scoping can be tremendously confusing. The following examples > should help to clarify the present state of affairs. > > $ x() { local a; y; echo "outer: $a"; } > $ y() { local a; a=123; echo "inner: $a"; } > $ x; echo "outermost: $a"

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

2024-03-10 Thread Zachary Santer
On Sun, Mar 10, 2024 at 1:51 PM Kerin Millar wrote: > $ y() { local -g a; a=123; echo "inner: $a"; } > $ x; echo "outermost: $a" > inner: 123 > outer: 123 > outermost: > > This may not be. There, the effect of the -g option effectively ends at the > outermost scope in which the variable, a, was d

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

2024-03-10 Thread Kerin Millar
On Sun, 10 Mar 2024 23:09:37 +0800 Adrian Ho wrote: > [Apologies, an earlier edition of this bug report was sent from the address > a...@lex.03s.net, which can only be replied to from my internal network. > Please ignore that report. Thanks much!] > > Configuration Information [Automatically gen

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

2024-03-10 Thread Adrian Ho
[Apologies, an earlier edition of this bug report was sent from the address a...@lex.03s.net, which can only be replied to from my internal network. Please ignore that report. Thanks much!] Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler:

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

2024-03-10 Thread aho+lex
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc-11 Compilation CFLAGS: -DSSH_SOURCE_BASHRC uname output: Linux lex 6.5.0-25-generic #25-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 14:58:39 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux Machine Typ