When I use arithmetic expansion in an array index in bash, like this:
declare -a FILES
declare -i INDEX=0
for FILE in ./*
do
FILES[((INDEX++))]="$FILE"
done
Do I need a dollar sign in front of ((...))
?
So does it have to be:
FILES[((INDEX++))]="$FILE"
or rather:
FILES[$((INDEX++))]="$FILE"
?
In my local copy of bash both variants seem to work - it's version 4.3.30.
I would expect only the latter to work, because I think only that one returns the result of the arithmetic expression. But there: Bash - arithmetic in array index I've read that only the first might work with older versions of bash (?). So which one is actually correct? And why is the first one working? I haven't found a specific answer to that yet.
See Question&Answers more detail:os