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

查看:26
本文介绍了在 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"

当我这样写时没有问题:

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.

来自 ubuntu 10.04 下 bash 版本 4.1.5 的联机帮助页.

From the manpage of bash version 4.1.5 under ubuntu 10.04.

以下来自 Chet Ramey(截至 2011 年的当前 bash 维护者)的声明可能是关于此错误"的最官方文档:

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