zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Lawrence Velázquez" <larryv@zsh.org>
Cc: Roman Perepelitsa <roman.perepelitsa@gmail.com>,
	Michael Smith <michael.smith@cloudera.com>,
	 Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Bug: 'export FOO' not idempotent
Date: Sat, 2 Jul 2022 15:05:44 -0700	[thread overview]
Message-ID: <CAH+w=7bm-X5mPBWvZfxStc4HwwdrKuP5T5rTyHmmd0MH37UNeg@mail.gmail.com> (raw)
In-Reply-To: <5f14e266-e12c-474b-9366-48ed035de392@www.fastmail.com>

On Mon, Jun 27, 2022 at 3:39 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Mon, Jun 27, 2022, at 5:58 PM, Roman Perepelitsa wrote:
> > The problem is that `export FOO` doesn't export anything.

You're seeing the intersection of two historic behaviors.  "export
FOO" doesn't export anything because it's not possible to have an
environment string that has no value (more on this below).  "typeset
-p" outputs a statement containing an assignment with an empty string
because FOO is not unset ($+FOO is 1) and there's no other way to
represent that in a typeset command.  Historically, it would have
output
  typeset -gx FOO=''
instead of
  export FOO=''
but that was changed at https://www.zsh.org/workers/39704 after a
discussion similar to this discussion.  In 39704:

>>>There has previously been discussion of the fact that zsh differs in
>>>this regard -- namely, that declaring a variable implies that it has
>>>become set, and you must thereafter explicitly unset it -- but zsh
>>>also handles environment variables differently, in that the value is
>>>not actually exported until it is explicitly assigned, even though
>>>the variable appears to be set.

Incidentally, also refer https://www.zsh.org/workers/39758 and thread.

> > Moreover, the subsequent `typeset -p FOO` says that FOO *is* exported.

The actual *envp C-string can't contain "...:FOO:..." (each
colon-separated element must have an equal sign).  So in your example
here --

> >   % typeset -p FOO
> >   typeset: no such variable: FOO
> >   % export FOO
> >   % typeset -p FOO
> >   export FOO=''
> >   % env | grep FOO
> >   FOO

-- what might actually be printed at the last step is

  FOO=

> I agree that that would make more sense.  The current behavior is
> rather odd.

Possibly, but it's that way because "not actually exported until
explicitly assigned", which if I try to reconstruct past decisions was
probably an attempt to make the environment behave as if (the now new
option) TYPESET_TO_UNSET was in effect even though the shell
internally did not do so.


  reply	other threads:[~2022-07-02 22:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27 21:11 Michael Smith
2022-06-27 21:43 ` Lawrence Velázquez
2022-06-27 21:46   ` Michael Smith
2022-06-27 21:52     ` Lawrence Velázquez
2022-06-27 21:58       ` Roman Perepelitsa
2022-06-27 22:37         ` Lawrence Velázquez
2022-07-02 22:05           ` Bart Schaefer [this message]
2022-07-02 22:14             ` Bart Schaefer
2022-06-27 21:50   ` Roman Perepelitsa

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='CAH+w=7bm-X5mPBWvZfxStc4HwwdrKuP5T5rTyHmmd0MH37UNeg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=larryv@zsh.org \
    --cc=michael.smith@cloudera.com \
    --cc=roman.perepelitsa@gmail.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).