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

Re: ${^var} and word splitting



2014-11-24 11:12:01 +0000, Peter Stephenson:
> 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.

OK thanks. that's a difference from other shells I was not aware
of and it seems to be as documented indeed.

The source of my confusion can be simplified to:

~$ a='  1 2   3     '
~$ printf '%s\n' "${=a}"

1
2
3

~$


In other shells, leading/trailing _IFS white space_ characters
are ignored as part of word splitting, not in zsh.

If I understand correctly, in zsh the removing of those are
accounted to null-removal in things like:

$ print -l $=a
1
2
3

But then it's not clear why they are removed there and not in:

a=':a::b:'
IFS=:
print -l $=a

?


-- 
Stephane



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