I have a really stupid question, but I would just want to confirm. I have internally tested it as well with the following code.
for x in ${!test_array[@]}
do
echo hey
done
So my question is, apparently the for
loop will simply ignore anything between doing and done if the array is empty. I have tested it, and if the array is empty, echo hey
will never be run, which means the script will never bother doing anything within do ..
and done
. If the array has at least one element, then it will run echo hey
.
I just want to confirm if my understanding is correct. I mean from my testing it definitely seems to be that way.
"${!test_array[@]}"
with quotes there. See https://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters and you can thank us later. – ilkkachu May 27 '22 at 15:41for x in ; do echo hey; done
-- "what the shell sees" after parameter expansion – glenn jackman May 27 '22 at 16:46