Sorry to necromancer this thread; however, it is the top search result on Google from linuxquestions.org for 'read whole line bash'.
So, in the interest of helping out googlers, like myself, I'm going to post the solution to this here. This will hopefully help others, but mainly, it will help me the next time I forget how to do this and I consider changing my IFS.
Given a file with lines that contain spaces, such as this:
Code:
[user@box ~]$ cat blah
thislinehasnospaces
this line has spaces
these
are
separate
lines
This is another line with a variety of spaces
you can read in whole lines using
"read -r", thusly:
Code:
[user@box ~]$ while read -r sillyvariable; do echo "$sillyvariable"; done < blah
thislinehasnospaces
this line has spaces
these
are
separate
lines
This is another line with a variety of spaces
So, there it is.
Again,
sorry to necro the thread.