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

Re: unexpected clearing of parameter flags with ::=



On Mon, May 2, 2022 at 9:46 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>
> % typeset -Z3 i
> % echo ${i=5}
> 005
> % echo ${i:=15}
> 005
> % echo ${i::=15}
> 15
At this point,
% echo ${i}
015

>
> The manpage says
>  ${name::=word}
>   In the first form, if name is unset then set it to word; in the second
>   form, if name is unset or null then set it to word; and in  the  third
>   form,  unconditionally  set  name to word.  In all forms, the value of
>   the parameter is then substituted.
>
> which to me doesn't imply that the parameter is reset first,
> especially since it isn't reset for the first form. I'm a little
> confused as to why this doesn't assign the value either:
>
> % unset i
> % typeset -Z3 i
> % echo ${i:=25}
This actually echoes three spaces (not included in my original mail apparently):
% echo _${i:=25}_
_   _


> but this does set it:
> % unset i
> % typeset i
> % echo ${i:=25}
> 25
and again, echo ${i} here shows 025 as expected.

> I thought maybe -Z3 causes the implicit value to be 000 but it is
> printed as empty, so shouldn't it fulfil the "unset or null" condition
> despite the -Z flag being active?

The -Z3 implicit value does take effect, but because there is no
digit, it is padded with spaces instead of zeroes, which I apparently
overlooked.

So to clarify my original confusion, := does nothing on a parameter
declared with typeset -Z3 because it expands to be padded before
checking if it's "empty", despite actually being unset, and ::= shows
the assigned value ignoring the parameter flags (but the flags aren't
actually cleared, they just aren't used for the particular expansion
that used ::=).

Would we consider either or both of these to be bugs?

-- 
Mikael Magnusson




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