Bash 间接数组寻址? [英] Bash indirect array addressing?

查看:27
本文介绍了Bash 间接数组寻址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一些 bash 数组:

Suppose I have some bash arrays:

A1=(apple trees)
A2=(building blocks)
A3=(color television)

和索引J=2,如何获取A2的数组内容?

And index J=2, how to get the array contents of A2?

推荐答案

我已经找到了解决方案,可以通过以下方式解决:

I've already found a resolution, this can be done by:

$ Aref=A$J
$ echo ${!Aref}
building
$ Aref=A$J[1]
$ echo ${!Aref}
blocks
$ Aref=A$J[@]
$ echo "${!Aref}"
building blocks

这篇关于Bash 间接数组寻址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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