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

Re: Is outer quoting not needed (docs say "redundant")?

On Tue, 12 Dec 2017 14:41:26 +0100
Sebastian Gniazdowski <psprint@xxxxxxxxxxx> wrote:
> manual says:
> "in "${(@f)"$(foo)"}", there are two sets  of quotes,  one
>  surrounding  the whole expression, the other (redundant) surrounding
> the $(foo) as before."
> One user reported that single, outer quoting always worked for
> him. Word "redundant" quite confirms this, but can we be sure?

The quoting is done at an early stage, by the lexical analyser.  Double
quotes are handled as a special form of analysis (function
dquote_parse()) ensuring that

- everything in the quotes is marked as being within the quotes;

- in particular, "$" are tokenised differently compared with "$"
outside double quotes, so the parameter substitution behaves

- ${ ... } expressions must complete before the end of the quotes --- so
double quotes internally are noted as tokens but don't affect the top
level parsing.

The internal double quotes show up as part of the argument of the
parameter substitution because they're not removed until we've analysed
the substitution.  So if necessary they will flag up the fact that the
internal expression is double quoted.  But because the parameter
substitution in this case is already double quoted, they have no
additional effect.

There may be a better example to use in the manual: the example here
uses the "@" flag for splitting, which is only meaningful if the outer
quotes are present.  But it does have the use of pointing out that
the double quotes are nested --- which might not be obvious, you
might naively think the "${" and "}" were in two different
double-quoted expressions.


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