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

Re: field splitting with empty fields



Stephane Chazelas wrote:
> > It's odd it removes the space even if quoted:
> > 
> > % foo="one:two::four:five"
> > % print -l "${(@s.:.)foo}"
> > one
> > two
> > four
> > five
> [...]
> 
> I've always known it to behave like that, I even thought it was
> documented but I can't find it now in the manual so maybe it
> wasn't.
> 
> I've myself already relied on it before, though many other
> times, it's true I have wished it was not removing empty items.

The interesting question is:  are there times when you need the double
quotes (for some other reason), but *still* don't want empty elements
removed?  That would explain the kludge.

I certainly agree that

% print -l ${(s.:.)foo}

*should* remove empty elements.

We could in any case apply no-removal behaviour to the version with the
"@" flag (which we can detect even though it's not current having a
special effect in the expression at the top).  That seems
unobjectionable, since the presence of the "@" specifies "$@"-like
behaviour.  I'll do that if no one can see a further objection, though
it still leaves the kludge.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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