[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
"local -g" declaration references local var in enclosing scope
From: |
Adrian Ho |
Subject: |
"local -g" declaration references local var in enclosing scope |
Date: |
Sun, 10 Mar 2024 23:09:37 +0800 |
[Apologies, an earlier edition of this bug report was sent from the address
aho@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: 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 Type: x86_64-pc-linux-gnu
Bash Version: 5.2
Patch Level: 26
Release Status: release
Description:
"local -g var" incorrectly references a local variable in an
enclosing scope, while "local -g var=val" correctly references and modifies
the global variable.
Repeat-By:
Test script:
#!/usr/bin/env bash
echo "Bash version: $BASH_VERSION"
b() {
local -g a=2
c
}
c() {
local -g a
a=3
}
y() {
local z=1
x
}
x() {
local -g z=2
w
}
w() {
local -g z
echo "w: z=$z"
z=3
}
b; y
echo "a=$a z=$z"
Expected output:
Bash version: 5.2.26(1)-release
w: z=2
a=3 z=3
Actual output:
Bash version: 5.2.26(1)-release
w: z=1
a=3 z=2
- "local -g" declaration references local var in enclosing scope,
Adrian Ho <=
- 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, 2024/03/10
- 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