bug-bash
[Top][All Lists]
Advanced

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

Re: Trailing null fields are discarded while leading ones are preserved


From: Chet Ramey
Subject: Re: Trailing null fields are discarded while leading ones are preserved
Date: Tue, 19 Dec 2006 10:00:45 -0500
User-agent: Thunderbird 1.5.0.8 (Macintosh/20061025)

Stahlman Family wrote:

> I guess the question is, what is meant by "delimits a field" in the
> following excerpt from the Bash manual?
> 
> "Any character in IFS that is not IFS whitespace, along with any
> adjacent IFS whitespace characters, delimits a field."
> 
> I suppose I'm interpreting it to mean "separates fields". It occurred to
> me that perhaps it means "terminates a field". The problem with that
> definition, however, is that if I add any single character after the
> final '|' in the example above, string_extract_verbatim will extract a
> final field, which is not terminated by anything in IFS, but simply by
> the end of the string. In that case, the final IFS delimiter is
> separating the final two fields. The bottom line is that since the Bash
> manual does not appear to distinguish between the cases of leading and
> trailing null fields, it appears that an arbitrary design choice
> determines that leading null fields are kept, and trailing ones are not.

The Posix committee has debated this issue several times.  In fact, there
is a standards interpretation (from 1995!) declaring that "delimiter"
must be used as "field terminator" (and the standard consistently uses
"delimiter").

The Posix rules are at

http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_05

Bash follows them faithfully.  The language isn't perfect, but there is
practical consensus among shell implementations.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                       Live Strong.  No day but today.
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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