From: Stephane Chazelas <stephane@chazelas.org>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: "typeset -p" and no_GLOBAL_EXPORT, other misc.
Date: Tue, 12 Mar 2024 20:26:53 +0000 [thread overview]
Message-ID: <20240312202653.p2bbwbpxcfazzgpj@chazelas.org> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2024-03-12 20:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 4:13 Bart Schaefer
2024-03-12 8:49 ` Stephane Chazelas
2024-03-12 18:32 ` Bart Schaefer
2024-03-12 20:06 ` Stephane Chazelas
2024-03-12 20:31 ` Bart Schaefer
2024-03-12 20:48 ` Stephane Chazelas
2024-03-12 21:02 ` Bart Schaefer
2024-03-12 20:26 ` Stephane Chazelas [this message]
2024-03-12 20:38 ` Bart Schaefer
2024-03-12 20:58 ` Stephane Chazelas
2024-03-12 21:03 ` Bart Schaefer
2024-03-13 0:52 ` {PATCH] (for real this time) " Bart Schaefer
2024-03-14 2:11 ` [PATCH] More "typeset -p" and GLOBAL_EXPORT Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240312202653.p2bbwbpxcfazzgpj@chazelas.org \
--to=stephane@chazelas.org \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).