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

 

posted @ 2020-02-12 15:02  雨落寒沙  阅读(22067)  评论(1)    收藏  举报