[Top][All Lists]

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

Re: Empty trailing fields ignored by read

From: Chet Ramey
Subject: Re: Empty trailing fields ignored by read
Date: Mon, 02 Sep 2013 20:50:40 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130328 Thunderbird/17.0.5

On 8/29/13 12:42 PM, DJ Mills wrote:
> When using a non-default IFS (a default IFS would trim them), a single
> empty trailing field is ignored for read -a.
> IFS=: read -rd '' -a arr < <(printf %s ':foo:bar:'); printf '<%s> '
> "address@hidden"; echo
> <> <foo> <bar>
> I would expect the output to be:
> <> <foo> <bar> <>

The bash behavior is correct.  Characters in IFS are delimiters that are
treated as field *terminators* by word splitting, not technically as field
separators.  Posix-2013 (Issue 7 TC 1) clarifies this, and I just cribbed
some text from it for the bash documentation.

None of the special handling that sets variables to null strings takes
place, since there are not really more (or fewer) variables than fields.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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