It did not iterate over all globs because the condition of the loop was
while [[ "$i" -le "$#" ]]; do
but in the loop i was incremented but the num args left was decremented
thus they went in opposite orders. Instead record how many globs are
there first and check i against that.