On Sun, Mar 10, 2024 at 1:51 PM Kerin Millar <k...@plushkava.net> 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 declared. Namely, that of the x > function.
Pretty sure what's going on there is that "a=123" here is just setting the value of the variable a from the innermost scope where it's declared, and has nothing to do with declaring a different, global variable a immediately prior. Relatedly, how would one set attributes on a variable declared in a calling function? 'readonly' and 'export' can do it for their respective attributes, but otherwise, I think you just can't.