for loop
oceanMIH opened this issue · comments
oceanMIH commented
for ((i=0;i<${#arr[@]};i++)); do
printf '%s\n' "${arr[i]}"
done
the above code may be wrong if the array is not contiuous, or there are holes in the array
for example:
arr=(apple [3]=banana [6]=cherry)
andry81 commented
You can recreate array:
arr2=("${arr[@]}")
oceanMIH commented
You can recreate array:
arr2=("${arr[@]}")
yes, thanx
I think the following is better:
for i in ${!arr[@]}; do
printf '%s\n' "${arr[i]}"
done
MegaV0lt commented
Also should work without loop:
printf '%s\n' "${arr[@]}"