Process a file line-by-line in bash
From Birnam Designs Wiki
Processing a file line-by-line in bash:
OLDIFS="$IFS"; IFS=$'\n'; for line in $(cat imgs.txt); do echo "line: $line"; done IFS="$OLDIFS"
Setting the IFS to a newline (note the special newline syntax IFS=$'\n') prevents the for loop to iterate over spaces as well, which causes problems if there are any spaces in the lines of the file.