I was trying to print an index number along with the value of an array. I didn't know how to do it and figured it out via someone else's past post on this site. They basically added a ! in the "for" statement. But I actually don't understand what the "!" is actually doing, please can someone tell me, so I can understand why this works (i.e. prints out the index of $i rather than the value)?
$ cat test6
declare -a car_models
car_models=( honda toyota bmw )
for i in "${!car_models[@]}" ## Meaning of ! in this line plz
do
echo " $i ${car_models[$i]}"
done
$ ./test6
0 honda
1 toyota
2 bmw