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

Re: [bug] shwordsplit not working on $@ when $# > 1

On Wed, 10 Aug 2016 10:28:36 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> torch% x=(a:b "c d" ef)
> torch% print -l ${(s.:.)x}
> a
> b c d ef

That's correct, that's forced joining, which is documented.  As I said
in my previous email, it's not clear it's actually a lot of use.

> torch% print -l ${(@s.:.)x}
> a:b
> c d
> ef
> The second one used to work exactly like the first one,
> and is the one that worries me the most.

I think it should only cause a visible effect in double quotes as that's
its real point --- though I wouldn't be surprised if there were already
exceptions.  It's hard to see how it could be interpreted to mean ignore
the (s.:.), even if there are double quotes.

You might also hope that logically this would have the same effect as
${(s.:.)@} when the contents of $@ were the same as the contents of $x,
regardless of context (i.e. whether or not in double quotes).  Possibly
that conflicts with the principle that it has no effect outside double
quotes, but I can't think of a case.  To be clear: it is not a conflict
that SHWORDSPLIT behaviour and (s...) behaviour differ from one another,
e.g. with respect to forced joinging, only if expressions
involving the same modifications to ${(@)x} and $@ differ when the
contents of the arrays and the contexts are the same.

Note the documented oddity of the behaviour of (s...) in double quotes
when (@) does *not* also appear.  But as far as I know the combination
of the two has always behaved rationally by zsh standards.

> Then there's this weird edge case, where an empty $IFS acts like you
> have specified the (@) flag when shwordsplit is set:
> torch% IFS=
> torch% setopt shwordsplit
> torch% print -l ${(s.:.)x}
> a:b
> c d
> ef

Hmm... I would guess that what's happened is without an IFS forced
joining with a default separator fails, and because it didn't get joined
we refuse to split it (I think there was a sort of vague assumption at
one time that it only made sense to split a scalar into an array, rather
than an array into multiple arrays, though there are obviously
exceptions so this isn't much use as a rule).  That's probably a bug ---
I would think the most logical answer here is it should have been joined
with no separator and then split, but I doubt this has ever been thought
about before.

I wouldn't expect SHWORDSPLIT to make a difference if forced splitting
is in use, but that's another cavalier statement.


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