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

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

问题描述

我无法从一个bash脚本输出数组这样的另一个bash脚本:

 出口myArray的[0] =你好
出口myArray的[1] =世界

当我写这样没有问题:

 出口myArray的=(你好,世界)

有关几个原因,我需要我的数组初始化成多行。你有什么解决办法吗?


解决方案

  

数组变量可能(还)没有出口。


从bash的版本4.1.5手册页ubuntu下10.04。

从切特雷米(当前bash的维护者2011年)下面的语句大概是这个错误最官方文档:


  

是不是真的有一个很好的方式连接code数组变量到环境中。


<一个href=\"http://www.mail-archive.com/bug-bash@gnu.org/msg01774.html\">http://www.mail-archive.com/bug-bash@gnu.org/msg01774.html

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

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

When I write like this there are no problem:

export myArray=("Hello" "World")

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

解决方案

Array variables may not (yet) be exported.

From the manpage of bash version 4.1.5 under ubuntu 10.04.

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天全站免登陆