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

Re: Global array actually not available



On Jun 30,  4:34pm, Sebastian Gniazdowski wrote:
}
} In code, I declare reply2 and reply3 as arrays via typeset -ga. I do
} this from inside of a function. When the code returns to outer scope,
} (t)reply2 and (t)reply3 show empty strings.

I see your follow-up in which it appears this may be attributable to
separate shell processes, but in addition please note that typeset -g
does not actually declare a "global" variable (despite the mnemonic).
It merely declares a "non-local" variable.  The actual dynamic scope
of the variable will be the nearest surrounding scope in which that
parameter's name is already defined (even if both defined AND unset;
in the unset case it may become set again, but it's scope remains).

Thus "typeset -g name" declares a true global $name only when there
is not another $name already declared (or $name is already global,
of course).



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