bug-bash
[Top][All Lists]
Advanced

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

Re: Read stdin delimited fails on empty field


From: Chet Ramey
Subject: Re: Read stdin delimited fails on empty field
Date: Thu, 7 Jul 2016 22:27:27 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.1

On 7/7/16 3:01 PM, Todd Merriman wrote:

> Bash Version: 4.2
> Patch Level: 46
> Release Status: release
> 
> Description:
>         IFS='   ' # TAB
>         program_outputting_tab_delimited_fields |
>         while read -r FLD1 FLD2 FLD3 FLD4
>         do
>                 echo field1=$FLD1
>                 echo field2=$FLD2
>                 echo field3=$FLD3
>                 echo field4=$FLD4
>         done
> 
> Repeat-By:
>         If any fields are empty, the data is read into the preceding field.
>         In other words, if in the example FLD3 is empty, FLD4 is read into
>         FLD3.  If FLD2 and FLD3 are empty, FLD4 is read into FLD1.

This is the correct behavior.  Sequences of multiple whitespace characters
delimit fields, as long as those whitespace characters are in $IFS.  This
is explained in the man page, in the paragraph that begins:

"The shell treats each character of IFS as a delimiter..."

It reads, in part, "A sequence of IFS whitespace characters is also
treated as  a  delimiter."  The paragraph explains what IFS whitespace
characters are.

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



reply via email to

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