Let's say you have a file called file.txt, and you would like to iterate through it in a script. you can easily use the internal file separator in Bash to help loop through your results.

The interal file seperator will specify how data boundaries are interpretted by Bash. This is stored in the $IFS env variable. By default, when $IFS is not set, this will be any whitespace. However, we can set this to be a newline character.

Here is a quick example of how to achieve this in a Bash script:

$ IFS=$'\n'; for line in `cat file.txt`; do echo $line; done

To restore your internal file seperator to the default, just unset the variable:

$ unset IFS