Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 4
    +1 Thanks for some useful insights of the different treatments on space/tab vs "others" in IFS in bash... I knew they were treated differently, but this explanation simplifies it all a lot. (And the insight between bash (and other posix shells) and the regular sh differences is usefull too to write portable scripts!) Commented Jun 12, 2015 at 12:34
  • At least for bash-4.4.19, while read -r; do echo "'$REPLY'"; done works as while IFS= read -r line; do echo "'$line'"; done. Commented May 28, 2018 at 14:25
  • 1
    This: "...that erroneous notion that read is the command to read a line..." leads me to think, that if using read to read a line is erroneous, there must be something else. What could that non-erroneous notion be? Or is that first statement technically correct, but in truth the non-erroneous notion is: "read is the command to read words from a line. Because it's so powerful, you can use it to read lines from a file by doing: IFS= read -r line" Commented Jul 16, 2018 at 15:24
  • If you write IFS=$'\n', is that the same as IFS= but with the trailing \n stripped off the end of each line? Commented Oct 6, 2023 at 17:05
  • 1
    @shadowtalker, though you do sometimes see IFS=$'\n' read -r line being used here and there, it is pointless as read -r line reads the input up to a newline, but the newline is not included in what is read, so read could never split on newline on the result. So it's exactly the same as IFS= read -r line. In any case, it's better than forgetting the IFS=. It could make sense if using a different delimiter as supported with-d in some read implementations. IFS=$'\n' read -rd '' record would read a NUL delimited record and remove leading and trailing newlines in it. Commented Oct 6, 2023 at 18:25