zsh-workers
 help / color / mirror / code / Atom feed
* Bug: 'export FOO' not idempotent
@ 2022-06-27 21:11 Michael Smith
  2022-06-27 21:43 ` Lawrence Velázquez
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Smith @ 2022-06-27 21:11 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

Environments tested:
- macOS 12.4, M1 chip, zsh 5.8.1 (x86_64-apple-darwin21.0)
- Ubuntu 20.04.4, zsh 5.8 (x86_64-ubuntu-linux-gnu)

If I repeat 'export FOO' to mark an environment variable not give it a
value, in bash it consistently does not show up in 'env':

$ export FOO

$ env | grep FOO

$ export FOO

$ env | grep FOO

but in zsh the 2nd invocation will set it to an empty string:

$ export FOO

$ env | grep FOO

$ export FOO
        $ env | grep FOO

FOO=


This is an issue only because a project I'm building uses an empty export
for documentation, and it makes that project annoying to work with.

[-- Attachment #2: Type: text/html, Size: 3513 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: 'export FOO' not idempotent
  2022-06-27 21:11 Bug: 'export FOO' not idempotent Michael Smith
@ 2022-06-27 21:43 ` Lawrence Velázquez
  2022-06-27 21:46   ` Michael Smith
  2022-06-27 21:50   ` Roman Perepelitsa
  0 siblings, 2 replies; 9+ messages in thread
From: Lawrence Velázquez @ 2022-06-27 21:43 UTC (permalink / raw)
  To: Michael Smith; +Cc: zsh-workers

On Mon, Jun 27, 2022, at 5:11 PM, Michael Smith wrote:
> Environments tested:
> - macOS 12.4, M1 chip, zsh 5.8.1 (x86_64-apple-darwin21.0)
> - Ubuntu 20.04.4, zsh 5.8 (x86_64-ubuntu-linux-gnu)
>
> If I repeat 'export FOO' to mark an environment variable not give it a 
> value, in bash it consistently does not show up in 'env':
> $ export FOO
>
> $ env | grep FOO
>
> $ export FOO
>
> $ env | grep FOO
>
>
> but in zsh the 2nd invocation will set it to an empty string:
> $ export FOO
>
> $ env | grep FOO
>
> $ export FOO                                                            
>            $ env | grep FOO
>
> FOO=

This was discussed in workers/47531 and the ensuing thread.

https://www.zsh.org/mla/workers/2020/msg01350.html

It was resolved in zsh 5.9 with the introduction of the TYPESET_TO_UNSET
option, but as per workers/47545, "[t]his is a long standing feature
of zsh, so the default behaviour is not going to change."

https://www.zsh.org/mla/workers/2020/msg01364.html


> This is an issue only because a project I'm building uses an empty 
> export for documentation, and it makes that project annoying to work 
> with.

Depending on a variable to be exported but unset is a curious design
decision to say the least.

-- 
vq


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: 'export FOO' not idempotent
  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:50   ` Roman Perepelitsa
  1 sibling, 1 reply; 9+ messages in thread
From: Michael Smith @ 2022-06-27 21:46 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1493 bytes --]

Thanks for responding! I searched a bit but hadn't made that connection. I
can work with that.

On Mon, Jun 27, 2022 at 2:44 PM Lawrence Velázquez <larryv@zsh.org> wrote:

> On Mon, Jun 27, 2022, at 5:11 PM, Michael Smith wrote:
> > Environments tested:
> > - macOS 12.4, M1 chip, zsh 5.8.1 (x86_64-apple-darwin21.0)
> > - Ubuntu 20.04.4, zsh 5.8 (x86_64-ubuntu-linux-gnu)
> >
> > If I repeat 'export FOO' to mark an environment variable not give it a
> > value, in bash it consistently does not show up in 'env':
> > $ export FOO
> >
> > $ env | grep FOO
> >
> > $ export FOO
> >
> > $ env | grep FOO
> >
> >
> > but in zsh the 2nd invocation will set it to an empty string:
> > $ export FOO
> >
> > $ env | grep FOO
> >
> > $ export FOO
> >            $ env | grep FOO
> >
> > FOO=
>
> This was discussed in workers/47531 and the ensuing thread.
>
> https://www.zsh.org/mla/workers/2020/msg01350.html
>
> It was resolved in zsh 5.9 with the introduction of the TYPESET_TO_UNSET
> option, but as per workers/47545, "[t]his is a long standing feature
> of zsh, so the default behaviour is not going to change."
>
> https://www.zsh.org/mla/workers/2020/msg01364.html
>
>
> > This is an issue only because a project I'm building uses an empty
> > export for documentation, and it makes that project annoying to work
> > with.
>
> Depending on a variable to be exported but unset is a curious design
> decision to say the least.
>
> --
> vq
>

[-- Attachment #2: Type: text/html, Size: 2270 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: 'export FOO' not idempotent
  2022-06-27 21:43 ` Lawrence Velázquez
  2022-06-27 21:46   ` Michael Smith
@ 2022-06-27 21:50   ` Roman Perepelitsa
  1 sibling, 0 replies; 9+ messages in thread
From: Roman Perepelitsa @ 2022-06-27 21:50 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: Michael Smith, Zsh hackers list

On Mon, Jun 27, 2022 at 11:44 PM Lawrence Velázquez <larryv@zsh.org> wrote:
> https://www.zsh.org/mla/workers/2020/msg01350.html
>
> It was resolved in zsh 5.9 with the introduction of the TYPESET_TO_UNSET
> option, but as per workers/47545, "[t]his is a long standing feature
> of zsh, so the default behaviour is not going to change."
>
> https://www.zsh.org/mla/workers/2020/msg01364.html

It's odd that `export FOO` doesn't have the same effect as `repeat 2
export FOO` when TYPESET_TO_UNSET is not in effect. Would it make more
sense for the first command to have the same effect as the second?
Another oddity that suggests the same resolution:

  % export FOO
  % typeset -p FOO
  % export FOO=''
  % env | grep FOO
  %

Either `export FOO` is doing something weird or `typeset p FOO` is lying.

Roman.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: 'export FOO' not idempotent
  2022-06-27 21:46   ` Michael Smith
@ 2022-06-27 21:52     ` Lawrence Velázquez
  2022-06-27 21:58       ` Roman Perepelitsa
  0 siblings, 1 reply; 9+ messages in thread
From: Lawrence Velázquez @ 2022-06-27 21:52 UTC (permalink / raw)
  To: Michael Smith; +Cc: zsh-workers

On Mon, Jun 27, 2022, at 5:46 PM, Michael Smith wrote:
> Thanks for responding! I searched a bit but hadn't made that 
> connection.

Ah, yes -- the discussion was about "typeset", but it also affected
commands like "export" and "local" which in zsh are basically just
"typeset" in disguise.

-- 
vq


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: 'export FOO' not idempotent
  2022-06-27 21:52     ` Lawrence Velázquez
@ 2022-06-27 21:58       ` Roman Perepelitsa
  2022-06-27 22:37         ` Lawrence Velázquez
  0 siblings, 1 reply; 9+ messages in thread
From: Roman Perepelitsa @ 2022-06-27 21:58 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: Michael Smith, Zsh hackers list

On Mon, Jun 27, 2022 at 11:52 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Mon, Jun 27, 2022, at 5:46 PM, Michael Smith wrote:
> > Thanks for responding! I searched a bit but hadn't made that
> > connection.
>
> Ah, yes -- the discussion was about "typeset", but it also affected
> commands like "export" and "local" which in zsh are basically just
> "typeset" in disguise.

I remember. I was following that discussion. Here the issue is
different. The problem is that `export FOO` doesn't export anything.
Moreover, the subsequent `typeset -p FOO` says that FOO *is* exported.
I think it should work as follows when TYPESET_TO_UNSET is not in
effect (the default):

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

Currently it works this the same way except for the last command,
which outputs nothing. I think it should output "FOO" like in the
hypothetical listing above.

Roman.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: 'export FOO' not idempotent
  2022-06-27 21:58       ` Roman Perepelitsa
@ 2022-06-27 22:37         ` Lawrence Velázquez
  2022-07-02 22:05           ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Lawrence Velázquez @ 2022-06-27 22:37 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Michael Smith, zsh-workers

On Mon, Jun 27, 2022, at 5:58 PM, Roman Perepelitsa wrote:
> On Mon, Jun 27, 2022 at 11:52 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>>
>> On Mon, Jun 27, 2022, at 5:46 PM, Michael Smith wrote:
>> > Thanks for responding! I searched a bit but hadn't made that
>> > connection.
>>
>> Ah, yes -- the discussion was about "typeset", but it also affected
>> commands like "export" and "local" which in zsh are basically just
>> "typeset" in disguise.
>
> I remember. I was following that discussion.

Yes, of course; you participated as well.  That explanation was for
Michael.

> Here the issue is
> different. The problem is that `export FOO` doesn't export anything.
> Moreover, the subsequent `typeset -p FOO` says that FOO *is* exported.
> I think it should work as follows when TYPESET_TO_UNSET is not in
> effect (the default):
>
>   % typeset -p FOO
>   typeset: no such variable: FOO
>   % export FOO
>   % typeset -p FOO
>   % export FOO=''
>   % env | grep FOO
>   FOO
>
> Currently it works this the same way except for the last command,
> which outputs nothing. I think it should output "FOO" like in the
> hypothetical listing above.

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

-- 
vq


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: 'export FOO' not idempotent
  2022-06-27 22:37         ` Lawrence Velázquez
@ 2022-07-02 22:05           ` Bart Schaefer
  2022-07-02 22:14             ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2022-07-02 22:05 UTC (permalink / raw)
  To: Lawrence Velázquez
  Cc: Roman Perepelitsa, Michael Smith, Zsh hackers list

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: 'export FOO' not idempotent
  2022-07-02 22:05           ` Bart Schaefer
@ 2022-07-02 22:14             ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2022-07-02 22:14 UTC (permalink / raw)
  To: Lawrence Velázquez
  Cc: Roman Perepelitsa, Michael Smith, Zsh hackers list

On Sat, Jul 2, 2022 at 3:05 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> The actual *envp C-string can't contain "...:FOO:..." (each
> colon-separated element must have an equal sign).

Obviously I'm mis-speaking of the elements of the "environ" array, but
in any case they do need "=".


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-07-02 22:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 21:11 Bug: 'export FOO' not idempotent 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
2022-07-02 22:14             ` Bart Schaefer
2022-06-27 21:50   ` Roman Perepelitsa

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).