shell中遍历数组的几种方式

#!/bin/bash

arr=(12 36 '你好')
length=${#arr}
echo "长度为:$length"

# for 遍历
for item in ${arr[*]}
do
 echo $item

done


i=0

# until遍历
echo until begin

until (( i++  > $length ))

do
 echo ${arr[(( i-1 ))]}
done

echo end

# for遍历

echo for  begin

for (( k=0; k <= $length; k++ ))

do
 echo ${arr[$k]}

done

i=0

echo while begin


#while遍历

while (( i++ <= $length  ))
do
 echo ${arr[(( i-1 )) ]}

done
原文地址:https://www.cnblogs.com/hetutu-5238/p/12299115.html