A simple test case: TEST=value foo() { local TEST unset TEST # even this doesn't help compgen -v | grep TEST declare -p TEST } foo As you can see, 'compgen -v' lists the variable even though it's unset and unusable in local scope.
This was raised on the bug-bash list in 2017 but Chet is not amenable to the notion of changing this behaviour, and it appears unlikely that he ever will be. See https://www.mail-archive.com/bug-bash@gnu.org/msg19438.html in particular. Somewhat related is that bash-5.0 added the "localvar_unset" option, which prevents unset from popping the value from an outer scope. # bash -c 'x=0; f1() { local x=1; f2; x=2; }; f2() { unset x; declare -p x; }; f1; declare -p x' declare -- x="0" declare -- x="2" $ bash -O localvar_unset -c 'x=0; f1() { local x=1; f2; x=2; }; f2() { unset x; declare -p x; }; f1; declare -p x' declare -- x declare -- x="0" I suppose that makes this CANTFIX.
Coincidentally, https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00134.html was posted today.
(In reply to Kerin Millar from comment #2) > Coincidentally, > https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00134.html was posted > today. I was wondering if you commented because of this or not :)
(In reply to Sam James from comment #3) > (In reply to Kerin Millar from comment #2) > > Coincidentally, > > https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00134.html was posted > > today. > > I was wondering if you commented because of this or not :) Believe it or not, it was entirely coincidental! Notwithstanding, I did just reply in the thread.