Whilst mralk3 suggestion to create an array is a good idea, the command supplied does not do this. To be an array the command substitution needs to be inside round brackets, like so:
I am also not a fan of using ls, so would probably change the above to a glob:
The negatives for both of these is that they will also include directories if there are any so you would need to test for them.
The benefit of the glob over the command substitution is that the glob will not split on white space.
Your loop would also then change to the more traditional for loop:
Code:
for (( i = 0; i < ${#a[*]}; i+=2 ))