[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "local -g" declaration references local var in enclosing scope
From: |
Lawrence Velázquez |
Subject: |
Re: "local -g" declaration references local var in enclosing scope |
Date: |
Sun, 10 Mar 2024 18:39:19 -0400 |
User-agent: |
Cyrus-JMAP/3.11.0-alpha0-251-g8332da0bf6-fm-20240305.001-g8332da0b |
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"
But you're right that it does have an effect. I overlooked attributes:
$ printvar() { printf '%s: <%s> <%s>\n' "$1" "$var" "${var@a}"; }
$ x() { local var; y; printvar outer; }
$ y() { local var; z; printvar inner; }
$ z() { local -gu var; var=hello; printvar innermost; }
$ x; printvar outermost
innermost: <hello> <>
inner: <hello> <>
outer: <> <>
outermost: <> <u>
--
vq
- Re: ${var@A}; hypothetical, related parameter transformations, (continued)
- Re: ${var@A}; hypothetical, related parameter transformations, Chet Ramey, 2024/03/21
- Re: ${var@A}; hypothetical, related parameter transformations, Zachary Santer, 2024/03/24
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Mike Jonkmans, 2024/03/19
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Chet Ramey, 2024/03/19
- Re: nameref and referenced variable scope, setting other attributes (was "local -g" declaration references local var in enclosing scope), Mike Jonkmans, 2024/03/19
- Re: "local -g" declaration references local var in enclosing scope, Chet Ramey, 2024/03/11
Re: "local -g" declaration references local var in enclosing scope, Lawrence Velázquez, 2024/03/10
Re: "local -g" declaration references local var in enclosing scope, Kerin Millar, 2024/03/11
Re: "local -g" declaration references local var in enclosing scope, Kerin Millar, 2024/03/11
Re: "local -g" declaration references local var in enclosing scope, Adrian Ho, 2024/03/11
Re: "local -g" declaration references local var in enclosing scope, Chet Ramey, 2024/03/11
Re: "local -g" declaration references local var in enclosing scope, Chet Ramey, 2024/03/11
Re: "local -g" declaration references local var in enclosing scope, Kerin Millar, 2024/03/11
"local -g" declaration references local var in enclosing scope, aho+lex, 2024/03/10