Given an array of two elements,
array=("foo bar" baz)
Using a for..in
loop with the "normal" syntax yields three iterations (elements of the array are expanded).
for element in ${array[@]}
do echo $element
done
Output:
foo
bar
baz
While a for..in
loop with the "index" syntax works as intended (elements are not expanded).
for i in ${!array[@]}
do echo ${array[i]}
done
Output:
foo bar
baz
Is there any way to use the first syntax construct as I intend (i.e. to get the same results as those I get using the second construct)?
GNU bash, version 4.1.2(1)-release