bash looping, checking exit codes and function / array argument passing archetype