gpt4 book ai didi

linux - 虽然 export gg 我得到了未绑定(bind)的变量 gg

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:50:47 25 4
gpt4 key购买 nike

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 全局化并在任何地方可用吗?如果不是,如何通过 include.sh 让 gg 在任何地方都可用?

更新

环境:

$ 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 - 虽然 export gg 我得到了未绑定(bind)的变量 gg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47835626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com