加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在bash中导出关联数组(哈希)?

发布时间:2020-12-16 01:18:38 所属栏目:安全 来源:网络整理
导读:相关,但不重复: How to define hash tables in Bash? 我可以定义和使用bash哈希,但我无法导出它,即使使用-x标志.例如,以下工作用于导出(并测试输出)正常的字符串变量: aschirma@graphics9-lnx:/$export animal_cow="moo"aschirma@graphics9-lnx:/$bash -c
相关,但不重复: How to define hash tables in Bash?

我可以定义和使用bash哈希,但我无法导出它,即使使用-x标志.例如,以下工作用于导出(并测试输出)正常的字符串变量:

aschirma@graphics9-lnx:/$export animal_cow="moo"
aschirma@graphics9-lnx:/$bash -c "echo $animal_cow"
moo
aschirma@graphics9-lnx:/$

但是,如果我尝试导出哈希:

aschirma@graphics9-lnx:/$declare -A -x animals
aschirma@graphics9-lnx:/$animals[duck]="quack"
aschirma@graphics9-lnx:/$echo ${animals[duck]}
quack
aschirma@graphics9-lnx:/$bash -c "echo ${animals[duck]}"

aschirma@graphics9-lnx:/$

似乎嵌套的bash shell在其范围内没有哈希.我也通过手动输入嵌套的bash shell并尝试以交互方式使用哈希来验证这一点.

将数组变量编码到环境中并没有什么好方法.看到
http://www.mail-archive.com/bug-bash@gnu.org/msg01774.html(Chet Ramey是bash的维护者)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读