在bash脚本中导出数组 [英] Exporting an array in bash script

查看:162
本文介绍了在bash脚本中导出数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能将数组从bash脚本导出到另一个bash脚本,如下所示:

I can not export an array from a bash script to another bash script like this:

export myArray[0]="Hello"
export myArray[1]="World"

当我这样写没有问题:

export myArray=("Hello" "World")

由于几个原因,我需要将我的数组初始化为多行。你有什么解决方案吗?

For several reasons I need to initialize my array into multiple lines. Do you have any solution?

推荐答案


数组变量可能还没有被导出。 p>

Array variables may not (yet) be exported.

从ubuntu 10.04下的bash版本4.1.5的联机帮助页。

From the manpage of bash version 4.1.5 under ubuntu 10.04.

以下来自Chet Ramey(目前的bash维护者截至2011年)的声明可能是关于这个bug的最正式的文档:

The following statement from Chet Ramey (current bash maintainer as of 2011) is probably the most official documentation about this "bug":


真的是将数组变量编码到环境中的好方法。

There isn't really a good way to encode an array variable into the environment.

http://www.mail-archive.com/bug-bash@gnu.org/msg01774.html

这篇关于在bash脚本中导出数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆