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

Re: ${^var} and word splitting



On Mon, 24 Nov 2014 09:56:37 +0000
Stephane Chazelas <stephane.chazelas@xxxxxxxxx> wrote:
> $ a='  1 2   3  '
> $ print -l $=a
> 1
> 2
> 3
> $ print -l x$^=a
> x
> x1
> x2
> x3
> x
> $ print -l x${^${=a}}
> x1
> x2
> x3
> 
> 
> Why the extra "x" lines with x$^=a ?

In the case of $^=a, the steps are

- split a.  There's whitespace start and end so you get null elements
  corresponding to those.
- add the x's in front
- remove remaining null elements, but there aren't any.

With nested expansion, you get

- split a: same result
- remove null elements (before the x's get added).
- add the x's
- remove null elements for this level (but there aren't any more)

C.f.

$ print -l x${^"${(@)=a}"}
x
x1
x2
x3
x

which has been told explicitly to keep the null elements despite the nesting.

-- 
Peter Stephenson <p.stephenson@xxxxxxxxxxx>  Principal Software Engineer
Tel: +44 (0)1223 434724                Samsung Cambridge Solution Centre
St John's House, St John's Innovation Park, Cowley Road,
Cambridge, CB4 0DS, UK



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