I'm populating an array in a loop:
for k in one two three; do
array+=( "$k" )
done
echo $k[0] # should print one, instead prints one[0]
echo $k[1] # should print two, instead prints one[1]
Why does this print one[0]
instead of one
?
I'm populating an array in a loop:
for k in one two three; do
array+=( "$k" )
done
echo $k[0] # should print one, instead prints one[0]
echo $k[1] # should print two, instead prints one[1]
Why does this print one[0]
instead of one
?
You need to change your syntax when accessing arrays. You can set them using array[0]=
but to access them you require ${array[0]}
rather than $array[0]
etc.