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

Re: auto-quoting inside braces in arguments



Daniel Shahaf wrote on Fri, 19 Feb 2021 16:10 +00:00:
> Bart Schaefer wrote on Thu, Feb 18, 2021 at 14:44:29 -0800:
> > On Thu, Feb 18, 2021 at 2:13 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> > >
> > > Hang on.  Why would it matter which style of quotes would have been
> > > used?
> > 
> > In your example, what if $foo and $baz have an opening and closing
> > quote in their values?

By the way, the scenario you're implying is this:
.
    eval ${:-'"one'}${(qq):-two}${:-'three"'}
.
where (qq) was deliberately used so as not to interact with the literal
double-quote marks already in the value.

This sort of construct means there are _two_ levels of parsing that are
going to happen — one for each type of quotes (for instance, two
«eval»s, or an «eval» that runs «sh -c») — and therefore, $two should be
quoted twice, as in «zsh -c 'eval '${(q)${(q)lorem}» (where the outer
(q) is only correct because the command name happens to be «zsh»).

> As I wrote in the part you'd snipped:
> 
> > > > normally $foo would be constructed to end on inter-token whitespace,
> 
> It's of course possible to write code where the number of q's in bar matters
> (for instance, «eval ${:-\$}${(q…):-lorem}»), but that falls under "don't do
> that".




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