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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM