迴圈陣列
for
迴圈:
arr=(a b c d e f)
for i in "${arr[@]}";do
echo "$i"
done
要麼
for ((i=0;i<${#arr[@]};i++));do
echo "${arr[$i]}"
done
while
迴圈:
i=0
while [ $i -lt ${#arr[@]} ];do
echo "${arr[$i]}"
i=$(expr $i + 1)
done
要麼
i=0
while (( $i < ${#arr[@]} ));do
echo "${arr[$i]}"
((i++))
done