include.sh
#!/bin/bash -
export gg
f() {
for i in "${gg[@]}"
do
echo $i
done
}
run.sh
#!/bin/bash -
set -o nounset
. include.sh || exit 1
f
我收到此错误
scripts/include.sh: line 5: gg[@]: unbound variable
export
关键字不是应该使 gg 全局化并在任何地方可用吗?
如果没有,如何使 gg 在 include.sh
中随处可用?
更新
环境:
$ cat /etc/*-release
NAME="SLES"
VERSION="11.4"
VERSION_ID="11.4"
PRETTY_NAME="SUSE Linux Enterprise Server 11 SP4"
最佳答案
旧版 Unix shell 不支持 ()
数组。您应该使用 bash
调用脚本,它们将按预期运行。
正如更新问题中所写,您需要在导出之前定义gg
:
gg=()
export gg
我测试了该补丁,它工作正常。
关于linux - 虽然导出 gg 我得到了未绑定(bind)的变量 gg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47835626/