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

Re: ${(q)...} for newline



On Tue, 25 May 2010 14:25:13 +0100
Stephane Chazelas <stephane_chazelas@xxxxxxxx> wrote:
> 2010-05-23 21:45:39 +0100, Peter Stephenson:
> > Also, would I be right in thinking this is an accident waiting to
> > happen?
> > 
> > % foo=(one '' three)
> > % print ${(q)foo}
> > one three
>
> Not in the first case though, as array expansion removes the
> empty elements.

I don't think that argument really works... consider:

% foo=(one '' three)
% print ${(j.X.)foo}
oneXXthree

In other words, flags are applied before empty elements are
stripped.  The same goes for most transformations on array elements,
whether zsh-specific or otherwise; I don't see why (q) should be
different.

However, we don't actually say in the (already long) manual entry giving
the rules for variable expansion at what part either quoting or empty
element removal takes place.  The latter appears to be the last thing of all,
i.e. at the point where we decide to insert this into the list of arguments
(or otherwise).  I should probably concoct something.


Bart wrote
> However, I suggest that (q-) continue to use the literal quoted newline.

Right, it's really there as minimal quoting for human readability.

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


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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