[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'read' primitive

From: Bob Proulx
Subject: Re: 'read' primitive
Date: Thu, 21 Aug 2008 23:37:08 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

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.


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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]