Clear CentOS 7.9, the simple bash script
function unexpected_behavior() {
local action="install"
typeset -g action="$action"
}
unexpected_behavior
typeset
If a local variable and typeset global variable names the same, after executing unexpected_behavior function no action variable in typeset.
[centos@ip-10-20-1-44 ~]$ ./test.sh
…
XDG_SESSION_ID=4
_=unexpected_behavior
unexpected_behavior ()
{
local action="install";
typeset -g action="$action"
}
CentOS 8 and Ubuntu have different behavior, action variable exists in typeset.
ubuntu@ip-10-20-1-166:~$ ./test.sh
…
XDG_SESSION_ID=1
XDG_SESSION_TYPE=tty
_=unexpected_behavior
action=install
unexpected_behavior ()
{
local action="install";
typeset -g action="$action"
}
Can you explain to me the reason for this strange behavior?
It was a bug fixed in bash 4.3
(
declareandtypesetare exact synonyms)