【发布时间】:2021-02-08 01:15:36
【问题描述】:
我正在尝试在循环中访问数组中的数据。
这个命令运行良好..
echo "text: ${hnr1[1]}"
还有这个:
echo "text: ${hnr1[$loopnr]}"
但是,这让我很头疼;
echo "text: ${hnr$loopnr[1]}"
将导致:
**: text: ${hnr$loopnr[1]}: bad substitution**
有人知道怎么解决吗?
编辑: 不要挂在循环上,这是我测试东西的一种方式.. 数据为:
array **hnr1** has **20** entries regarding **map 1**
array **hnr2** has **20** entries regarding **map 2**
所以我的最佳功能是:
' data=${hnr$mapnr[$field]} '
【问题讨论】:
-
你想用
echo "text: ${hnr$loopnr[1]}"做什么? “访问数据”如何?数据是什么格式的? -
数据在名为 hnr1 的数组中 --> hnr66 数据是字符串/整数
-
这是一个数组,还是这 66 个单独的变量?数组(通常)在 bash 中声明为
hnr=(value1 value2 …)。 -
hnr1 包含 20 个关于 map1 的值,hnr2 包含 20 个 map2 的值等等......