[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
"local -g" declaration references local var in enclosing scope
From: |
aho+lex |
Subject: |
"local -g" declaration references local var in enclosing scope |
Date: |
Sun, 10 Mar 2024 23:02:23 +0800 (+08) |
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 var in an enclosing
scope, while a "local -g var=val" correctly references the global scope.
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
- Re: "local -g" declaration references local var in enclosing scope, (continued)
- 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 <=