[Apologies, an earlier edition of this bug report was sent from the address
[email protected], 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