清除CentOS 7.9,简单的bash脚本
function unexpected_behavior() {
local action="install"
typeset -g action="$action"
}
unexpected_behavior
typeset如果局部变量和类型集全局变量名称相同,则在执行unexpected_behavior函数后,在类型集中没有操作变量。
[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和Ubuntu有不同的行为,在排版中存在动作变量。
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"
}你能给我解释一下这种奇怪行为的原因吗?
发布于 2022-11-04 16:42:35
https://stackoverflow.com/questions/74184073
复制相似问题