shell中遍历数组的几种方式

谁说我不能喝 提交于 2020-02-12 15:21:13
#!/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

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!