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

Re: local but persistent integer?



On Fri, Sep 16, 2022 at 12:43 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2022-09-16 10:44, Bart Schaefer wrote:
> > On Fri, Sep 16, 2022 at 8:19 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> >>           integer -x start="$(( $(date +%s%N)/1000000 ))"
> >>
> >> ... I need 'start' to persist between function calls which it does
> > Given that construct, it should not.
>
> ... so it's visible externally as you say, but it's not going away either.

Hm, this is possibly a bug, but it's also possibly an expected
side-effect of "export" that I've forgotten about.  My previous
statement is correct for string-scalars created with "typeset" and
"local" etc., but "integer" behaves differently.  I think this is
related to preserving the attributes of the variable (i.e., even if
unset, it remains an integer, so if you assign to it again it acts
like one) about which I believe I recall some discussion, but I don't
recall when it was implemented.

In any case it's not reliable to expect locally-declared variables to
behave this way, and I'd still recommend using -g or -gH instead of
-x.




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