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

Re: Date prompt expansion



On Mon, 26 Nov 2012 13:38:04 +0100
Mark van Dijk <lists+zsh@xxxxxxxxxxxxxx> wrote:
> I noticed something odd when I was trying to fill an associated array
> with these prompt expansions and the behaviour replicates into
> non-array variable assignments too. I suspect this is caused by a bug
> somewhere..
> typeset -A datetime DATETIME DateTime dATEtIME
> datetime=("month"     "${(%):-%D{"%m"}}"
>           "day"       "${(%):-%D{"%d"}}"
>           "ymdt"      "${(%):-%D{"%y%m%dT%H:%M"}}")
>
> datetime[ymdt]: 121126T13:35}
> datetime[day]: 26}
> datetime[month]: 11}
> DATETIME[ymdt]: 121126T13:35}
> DATETIME[day]: 26}
> DATETIME[month]: 11}
> 
> ^ notice the } at the end

The parameter expansion is terminated by the first "}" it comes across.
The "%D{" is then not terminated but it works anyway since it runs to
the end of the expression.  The remaining "}" is then just a normal
part of the string.  The easiest fix is probably to move the quotes:

datetime=("month"     "${(%):-"%D{%m}"}"
          "day"       "${(%):-"%D{%d}"}"
          "ymdt"      "${(%):-"%D{%y%m%dT%H:%M}"}")

pws



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