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

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



2024-03-12 11:32:41 -0700, Bart Schaefer:
[...]
> > In zsh, readonly var, when not emulating other shells is more
> > like typeset -r:
> 
> It should in fact be exactly like "typeset -r", and export should be
> exactly like "typeset +x".
[...]

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

~$ zsh -c 'a() { export a; a=2; echo $a; }; a=1; a; echo $a'
2
2
~$ zsh -c 'a() { typeset -x a; a=2; echo $a; }; a=1; a; echo $a'
2
2
~$ zsh -c 'a() { typeset -gx a; a=2; echo $a; }; a=1; a; echo $a'
2
2
$ 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

So in that way, they're different from readonly/typeset -r

That export -x seems bogus BTW as export doesn't accept the -x
option.

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.

$ zsh -c 'a() { typeset a; typeset -x a; a=3; typeset -p a; }; b() { local a=2; a; typeset -p a; }; a=1; b; typeset -p a'
typeset -x a=3
typeset a=2
typeset a=1


-- 
Stephane




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