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

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



On Apr 28,  5:46pm, Peter Stephenson wrote:
}
} It's annoyed me for a while now that single-quoting a value uses
} single quotes even where they're not needed, and with existing single
} quotes in the value at the start or end you get something quite messy.

Hmm.

} 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".

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.)

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".  Wrapping the entire
string is also consistent with (qqqq), which is distinct from (q) which
applies $'...' only where needed.



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