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

Re: "typeset -p" and no_GLOBAL_EXPORT, other misc.



On Tue, Mar 12, 2024 at 1:26 PM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> ITYM typeset -x

Yes, sorry, typo.

> but I find that export / typeset -x seem to
> behave like typeset -gx in that they don't make the variable
> local.

Yes, that's GLOBAL_EXPORT in action, as in the subject of this thread.
They're still exactly like each other, I didn't say they were like
some other shell's export or that they acted like -r.

> $ zsh -c 'a() { export a; a=3; typeset -p a; }; b() { local a=2; a; typeset -p a; }; a=1; b; typeset -p a'
> export -x a=3
> typeset -x a=3
> typeset a=1
>
> That export -x seems bogus BTW as export doesn't accept the -x
> option.

Indeed, that's a bug in the printparamnode() routine.

> To have a local export variable, it seems you need
> typeset var; typeset -x var or typeset var; export var instead
> of typeset -x var.

Just
  typeset +g -x var
will do it, or unsetopt GLOBAL_EXPORT (which is dangerous without the
patch at the start of this thread).




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