【发布时间】:2019-12-29 10:29:37
【问题描述】:
我想从第二个索引开始循环遍历数组的索引。我该怎么做?
我试过了:
myarray=( "test1" "test2" "test3" "test4")
for i in ${!myarray[@]:1}
do
# I only print the indices to simplify the example
echo $i
done
但不起作用。
显然这是可行的:
myarray=( "test1" "test2" "test3" "test4")
myindices=("${!myarray[@]}")
for i in ${myindices[@]:1}
do
echo $i
done
但如果可能的话,我想在 for 循环语句中合并所有内容。
【问题讨论】:
-
请说明数组是索引的还是关联的。
-
它是一个索引数组。为了完整起见,我添加了更多代码。
标签: arrays bash for-loop slice