bug-bash
[Top][All Lists]
Advanced

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

Re: unexpected behavior of 'read' builtin


From: Jan Schampera
Subject: Re: unexpected behavior of 'read' builtin
Date: Sat, 24 May 2008 10:24:09 +0200
User-agent: IceDove 1.5.0.14eol (X11/20080509)

Juliano F. Ravasi wrote:

>     The second one is that it chops leading and trailing whitespace
>     when you provide one variable for assignment, and not when you
>     use the default $REPLY.
> 
>     I don't know if these are intended behavior, but it doesn't seem
>     to be documented, leading to a surprise when you expect
>     something and get some other thing instead.
> 
> Repeat-By:
> 
> [...]
>
>     About trailing and leading whitespace:
> 
>     ~$ read <<< '  a   b  '; declare -p REPLY
>     declare -- REPLY="  a   b  "
> 
>     ~$ read VAR <<< '  a   b  '; declare -p VAR
>     declare -- VAR="a   b"
> 
>     Note how whitespace is removed when using $VAR, but not when
>     using $REPLY.

IMO the key for that behaviour is already in the docs:
"...with leftover words and their intervening separators assigned to
       the last name." (read with variable name supplied)
and here:
"If no names are supplied, the line read is assigned to the variable REPLY."

The difference I see is:
- with variable name supplied, it's split into words and leftover words
are stored with their intervening separators into the last variable
given. Since there is only one variable, the effect is what you see.
- without any variable name supplied (default: REPLY), the line (!) is
stored.

J.





reply via email to

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