Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug: 'export FOO' not idempotent
On Mon, Jun 27, 2022 at 3:39 PM Lawrence Velázquez <larryv@xxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author