我无法像这样将数组从 bash 脚本导出到另一个 bash 脚本:
export myArray[0]="Hello"
export myArray[1]="World"
当我这样写的时候没有问题:
export myArray=("Hello" "World")
出于多种原因,我需要将我的数组初始化为多行。你有什么解决办法吗?
最佳答案
Array variables may not (yet) be exported.
来自 ubuntu 10.04 下 bash 版本 4.1.5 的联机帮助页。
Chet Ramey(截至 2011 年的当前 bash 维护者)的以下声明可能是关于此“错误”的最官方文档:
There isn't really a good way to encode an array variable into the environment.
关于arrays - 在 bash 脚本中导出数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5564418/