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

标签 linux bash

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/

相关文章:

linux - 如何在 Linux 中控制计算机 RGB LED

linux - putty - 需要最近的标准输出

linux - Linux系统不忙时如何调度任务

linux - 按特定分隔符删除字符串

bash - 计算shell脚本中2个不同文件夹中具有相同内容的文件数量

linux - 编写 bash 脚本。需要一些关于如何创建这个的指导

c++ - 如何仅构建和安装 boost 库的特定部分?

android - usb_buffer_free 和 usb_buffer_alloc 的编译错误

html - Xidel 提取标签内的数据——原始输出

python - 如何有效地打印 JSON 对象列表?