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

Re: Unexpected ${%F{}} evaluation

On Wed, Dec 3, 2014 at 1:20 PM, Marc Finet <m.dreadlock@xxxxxxxxx> wrote:
> Hello,
>     # x="${(%):-%F{red}}XX"; echo $x
>     }XX
>     # x=${(%):-%F{red}}XX; echo $x
>     XX
> My questions are the following:
>  - is this behavior intended, i.e. break an expression inside ${} to
>    the first } ?

Yes, I believe so.  Inside double quotes, the second open brace has no
special meaning, so the first close brace that is encountered closes
the parameter expansion.

>    At first, I thought that it was a limitation (of ""), but
>    testing the second case showed me that correct parsing could be done.

I think the second case is parsed "correctly" only by accident.  In
the second case the braces are initially parsed as a brace expansion,
but as a special case a brace expansion with only one element is
replaced by the literal string including the braces.  If you "unsetopt
braceexpand" you get the first result for both examples.

It could be argued that this is a bug in braceexpand.

>  - is it normal that %F{xx works as %F{xx} ?

In prompts a percent-expando can end at either the closing brace or
the end of the string, whichever comes first ... because it doesn't
seem useful to have the prompt report a syntax error.  %F{xx would not
work that way if there were more prompt string following it.

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