[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "local -g" declaration references local var in enclosing scope
From: |
Zachary Santer |
Subject: |
Re: "local -g" declaration references local var in enclosing scope |
Date: |
Sun, 10 Mar 2024 15:55:07 -0400 |
On Sun, Mar 10, 2024 at 1:51 PM Kerin Millar <kfm@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.
- "local -g" declaration references local var in enclosing scope, Adrian Ho, 2024/03/10
- Re: "local -g" declaration references local var in enclosing scope, Kerin Millar, 2024/03/10
- Re: "local -g" declaration references local var in enclosing scope,
Zachary Santer <=
- nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/10
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Chet Ramey, 2024/03/13
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), alex xmb sw ratchev, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Greg Wooledge, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), alex xmb sw ratchev, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Greg Wooledge, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Greg Wooledge, 2024/03/14
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Zachary Santer, 2024/03/14