David Lütolf wrote: > 'read' does not properly set variable when line ends with a > <space> character > > Repeat-By: > ~$ echo "foo " > bar > ~$ read foo < bar > ~$ echo "-$foo-" > -foo- > > the output should of course be: -foo -
This question was discussed recently. Instead of repeating it here I will simply include a pointer to it. Here is a pointer to the previous discussion. http://lists.gnu.org/archive/html/bug-bash/2008-05/msg00101.html The read builtin splits input on IFS. The key part in the manual documenting 'read' behavior is where it says: The characters in IFS are used to split the line into words. Space is one of the IFS characters and therefore the input is split upon it. To get the entire line verbatim you would need to use the $REPLY variable. Again the key part of the manual says: If no names are supplied, the line read is assigned to the variable REPLY. Bob