I\'m having this code from http://bash.cyberciti.biz/guide/While_loop, used to read line by line from a file
file=/etc/resolv.conf
while IFS= read -r line
In this case, IFS
is set to the empty string to prevent read
from stripping leading and trailing whitespace from the line.
Changing IFS
is usually done to control how the input will be split into multiple fields. But in this case, because there's only one variable name given to read
, read
won't ever split the input into multiple fields regardless of the value of IFS
. It will, however, remove the leading and trailing whitespace as mandated in the POSIX specification (assuming the value of IFS
contains whitespace or is unset).
See the POSIX specification for read and field splitting for details about how it works.