TIR (today I remembered) that, if you use a loop with a while read, that creates a subshell, and any variables you declared beforehand won’t be accessible. I had to change it to a for with a backticked command.