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

Re: PATCH: improve ${(q)...}

Bart Schaefer wrote:
> } This fixes the problem.  Is there a good reason for making this a
> } different flag, or is altering (q) good enough?  I couldn't think of a
> } reason why you would need it to be verbose
> The proposed patch changes the behavior of nested (q) options rather
> significantly.  E.g., ${(qqq)${(qq)v}} becomes very different.  This
> could be important if the resulting string is going to be processed
> with "eval".

I don't follow that.  The quotation is present if the inner quotation
would cause the word to behave differently when unquoted.  Stripping
multiple levels of quotation should therefore still work.  Or are you
thinking of things like the example below?

> Also keep in mind what happens when strings are catenated by adjacency.
> x=\$foo
> y=bar
> foo=this
> foobar=that
> eval print ${x}${(qq)y}
> Would you really expect "that" rather than "thisbar"?  (Admittedly an
> edge case.)

I won't rely on my expectation here---it's different with backslash
quoting anyway.  However, you've certainly spotted a case I hadn't where
this changes the behaviour.  I can look for different letters...
Hmm, we could use qQ which is currently meaningless as a sort of
shorthand for "minimal quoting"...?

> Although it's true that we never "guaranteed" the quoting behavior,
> it's implicit in the doc:
>        ... If this flag is given twice, the resulting words
>        are quoted in single quotes and if it is given three times,
>        the words are quoted in double quotes ...
> Note it *doesn't* say "as if in <mumble> quotes".

OK, I see you can claim the annoying inconsistency with backslash is a

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