Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: "typeset -p" and no_GLOBAL_EXPORT, other misc.
- X-seq: zsh-workers 52733
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: "typeset -p" and no_GLOBAL_EXPORT, other misc.
- Date: Tue, 12 Mar 2024 20:26:53 +0000
- Archived-at: <https://zsh.org/workers/52733>
- In-reply-to: <CAH+w=7Z40c_8k1FHra0K9iQvih=4LZmS-pkx06o_CiDf0wTJJQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <CAH+w=7YBMPe_6qZPt8-CR_EhJPGbnyiNNAguGcWiD3K7nLtB9A@mail.gmail.com> <20240312084926.d6vbk75ozud7i2jm@chazelas.org> <CAH+w=7Z40c_8k1FHra0K9iQvih=4LZmS-pkx06o_CiDf0wTJJQ@mail.gmail.com>
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