I came across ${!i}
in the body of a for-loop of the form
for ((i=$#; i>0; i--)); do
# ...
if <SOME_TEST>; then
# ...
accumulator="${!i}:${accumulator}"
# ...
fi
# ...
done
Given this range of possible values, my guess is that ${!i}
means something like "expand as the i
-th positional argument".
Be that as it may, I'd like to know more about this notation. (In particular, is ${!i}
a special case for $@
, or is it a particular instance of a syntax applicable to any array? This is why I'm curious about how the expression gets parsed.)
I can't find documentation for this notation, though. If I search the bash
man page for the sequence ${!
, I find only the following strings
${!name[@]}
${!name[*]}
${!prefix*}
${!prefix@}
...and I can't fit the documentation surrounding these occurrences to the code I'm puzzling over.
(Actually, if possible, please quote any relevant documentation in your answer, so that I can sort out why I missed it.)
EDIT: For my original post I copied the wrong for
-line from the original code. I've fixed it now. (The interpretation is the same, though.)