循环数组
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