[Top][All Lists]

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

Re: printf '%s\n' "$@" versus <<< redirection

From: Chet Ramey
Subject: Re: printf '%s\n' "$@" versus <<< redirection
Date: Tue, 21 Feb 2023 17:01:30 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

On 2/21/23 4:15 PM, Mike Jonkmans wrote:

Reading that POSIX section is confusing indeed.

Starting with the first paragraph:
``After expansion ... the shell shall scan the results of expansions and
substitutions that did not occur in double-quotes for field splitting
and multiple fields can result.''

- Should each expansion be scanned this way
   or just the result after all expansions?

Each expansion is scanned, with the noted exceptions, after the word
expansions described in 2.6 are performed (tilde expansion, parameter
expansion, etc.). So all the named word expansions take place, left to
right, before the result is split. If no expansions took place, the word
isn't split -- even if IFS contains `%', you don't split ab%cd.

``3. ... The term " IFS white space" is used to mean any sequence
(zero or more instances) of white-space characters that are in the IFS value
(for example, if IFS contains <space>/ <comma>/ <tab>, any sequence of
<space> and <tab> characters is considered IFS white space).''

- "zero or more instances" Why zero? That could be problematic.

It's how the text handles the "Any adjacent IFS white space" (and
technically the "IFS white space ... at the beginning and end").

- Missing is a definition of 'white-space' characters.

It's defined elsewhere in the standard as

"A sequence of one or more characters that belong to the space character
class as defined via the LC_CTYPE category in the current locale.

In the POSIX locale, white space consists of one or more <blank> ( <space> and <tab> characters), <newline>, <carriage-return>, <form-feed>, and
<vertical-tab> characters."

Both <space> and <blank> are defined as being locale-dependent.

``3b. Each occurrence in the input of an IFS character
that is not IFS white space, along with any adjacent IFS white space,
shall delimit a field, as described previously.''

- The term 'IFS character' is slightly confusing.
   At first i thought that that would mean any of <space><tab><newline>.
   But it just means 'a character that is in IFS'.

That follows from the previous

"The shell shall treat each character of the IFS as a delimiter and use the
delimiters as field terminators"

- Nowhere is it stated that IFS characters are removed.
   Nor is it stated that IFS whitespace is removed.
   It seems implicit that characters, delimiting a field, are removed.

It follows from the example in 1, where the resulting fields do not contain
any IFS characters.

The authors have to assume some knowledge of how Unix shells work, since
the standard is simply codifying existing shell behavior. Shells have
always removed IFS characters.

Still the bash manpage is very nicely written.
Good job, Chet and all other contributors!


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU

reply via email to

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