Fix broken for loop when -a flag is used