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

Re: Unexpected ${%F{}} evaluation



On Wed, Dec 3, 2014 at 10:20 PM, Marc Finet <m.dreadlock@xxxxxxxxx> wrote:
> Hello,
>
> While hacking a small script I fall on the following case:
>
>     # x="${(%):-%F{red}}XX"; echo $x
>     }XX
>     # x=${(%):-%F{red}}XX; echo $x
>     XX
>
> In both cases, the color was correct, i.e. (%) + %F{} did it job, but
> note the extra } in the first case.
> It seems that the double-quotes of the first case associated the first
> '}' to the '${': its value is Outbrace in stringsubst(). The '{' after
> the %F and the second '}' remain {}, and the first { is Inbrace.
>
> In the second case, the two '}' are converted into Outbrace, and both
> '{' are also converted into Inbrace.
>
> For the first case, {} are not balanced according to what I expected,
> (outer {} for $ and inner {} for %F), but first } for first {, i.e. ${}.
>
> My questions are the following:
>  - is this behavior intended, i.e. break an expression inside ${} to
>    the first } ? At first, I thought that it was a limitation (of ""), but
>    testing the second case showed me that correct parsing could be done.
>  - is it normal that %F{xx works as %F{xx} ?
>
> Thanks,
>
> Marc.

To answer the unasked question, since Bart already answered,
% x="${(%):-%F{red\}X%F{green\}X%~}"; echo -E $x
and
% x=${(%):-%F\{red\}X%F\{green\}X%~}; echo -E $x
both work "as expected". (the -E is just to convince myself no stray
backslashes are left).

-- 
Mikael Magnusson



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