Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [doc] "sh_word_split nothing to do with word splitting"?



2018-03-16 11:28:23 -0700, Bart Schaefer:
> On Fri, Mar 16, 2018 at 10:26 AM, Stephane Chazelas
> <stephane.chazelas@xxxxxxxxx> wrote:
> > So, how about this new take at it? Renders (in info) as:
> >
> > SH_WORD_SPLIT (-y) <K> <S>
> >      Causes $IFS field splitting to be performed on unquoted parameter
> >      expansions in addition to command substitutions.  Note that
> 
> This is OK, I just keep thinking there should be a reference back to
> the shell grammar; field splitting applies to anything identified in
> the grammar by the token WORD provided that the WORD is not quoted.
> Arithmetic expressions are treated as if double-quoted.  That's really
> all there is to it.

Note that for $((text)), there's possible confusion. In the
POSIX spec, the reference to "as if double quoted" is about the
interpretation of text, not $((text)).

In POSIX, in $(($1 + 2)), $1 is not subject to split + glob
because $1 + 2 is treated as if quoted, but $(($1 + 2)) is
*required* (!) to be split+globbed.

As in:

IFS=2; echo $((11 * 11))

is *required* to output

1 1

but zsh, even in sh emulation outputs "121" as everyone would
expect.

That's why I mention it in the text to clarify that it's an
intentionaly deviation from the POSIX standard.

(I will try and have POSIX lift that silly requirement but I
have little hope they'll accept; note that a few shells have
already gone out of their way to change their sensible
behaviour to meet POSIX compliance on that front)

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author