Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Issue with VAR=foo cmd where VAR is a named reference
- X-seq: zsh-workers 54469
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Issue with VAR=foo cmd where VAR is a named reference
- Date: Mon, 4 May 2026 23:39:42 +0200
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=OwbQlqQzQXelZMGXfXu7gtI58Z4Xn/B1EZpgwSW7YZ0=; fh=YkFOm45xKl95+UAZDkDGZRSpLLmS3TpAyDTXxLUXfMg=; b=PvRpxsGHkTzfWdeBnbmxtJyy9JX+/N048skvlHnz/CzK/alGKP0OGWwKWgLwDFDR1m d8Wbgy1nhIaBpWKow0xLF1pM1rX5WT1VlDw6vi0BL3IZeTIs4DPPWB4J7VLc+UREAWG3 FLQSxnMsWMXUWdnoHe2IogCNc/14icJ93unryBoDijujfRtBO6qyF5e4+fFLrUw+gGWa XZz11/5to4TvhloAgLlYzhWVNqhlk1yXKCPCQPmev5xU/5Agy3tXPNX4bbL/35Q5IHB8 tuZ98M1I9P2KsHtOlmeCRAlrpwLMSxTfVosUud5Ia/8zQt60KOQ+0QHMBGgu31OAufxg 5cvA==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1777930795; cv=none; d=google.com; s=arc-20240605; b=Vvsk7joo2MFzfySynVGLaeCH0zD4vL1Y2GGuAAsGOcBZn5RnUNVmZUSbWZ979KrTiO 2e4btpvVVo5u1ZYICPTqNKzTzlMuzKTpyGSK56e1BCSMGDwCdQD64zhzmRQyH7gzddJr Lcw2TB7OP6BWAmaaLMbhb18+LlfCo/1oXgEwoJBSu1I2J3CrcMkI8/d6S59mEtmJ37QR 257OmoHIvWWL9hu6Dpq96+xCvE7p3fDLboiKBfq1n4lDhPR/mcQDWODJfVRJu8Mop+bY MIs98vI6scq7yTc38JZOOrkG3T9afutgJVnwyoNMgXZ1/KWj2Civ+7Nz3gnV+5vL5mJr qi1Q==
- Archived-at: <https://zsh.org/workers/54469>
- In-reply-to: <CAGdYchsM9JbZT4W9qdGSB7eT6X-=WiCj1wmd_ynb=m9uSys5Hw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchvh5Q+wG5au4=+-VDkZyvdu19-ac5gWsM-ZEGQm2_bgpw@mail.gmail.com> <CAH+w=7aapgt4Ag+ke-XHNy9XC8--nWH6eNTDWT=38PCHZUXk4g@mail.gmail.com> <CAGdYchsM9JbZT4W9qdGSB7eT6X-=WiCj1wmd_ynb=m9uSys5Hw@mail.gmail.com>
On Mon, May 4, 2026 at 6:19 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>>
>> Hmm, there's a complication here where you have to consider that (per
>> POSIX) some builtin commands preserve assignment to prefix environment
>> strings and some do not. I don't immediately recall which category
>> "typeset" falls into.
>
>
> I didn't know about that but the code to save and restore the assigned parameters is indeed conditional. If POSIXBUILTINS is enabled, typeset preserves the assignments:
>
> % setopt POSIXBUILTINS; var=foo; var=bar typeset -p var; typeset -p var
> typeset var=bar
> typeset var=bar
>
>> > Exporting named references is in principle possible
>>
>> I think that would be a bad choice. For security reasons it should
>> not be possible to import a named reference, and other programs would
>> have no idea what to do with an environment instrumented by zsh for
>> the purpose.
>
>
> I don't mean that it should be possible to export named references as something special that would be recognized as a named reference by a Zsh shell. I just mean that tagging a named reference R with -x could have for effect to augment the environment with the key value pair R=$R (if R refers to a non-array variable):
>
> % typeset var=foo
> % typeset -nx ref=var
> % printenv | grep ref=
> ref=var
> % zsh -c 'typeset -p ref'
> export ref=var
>
> In principle, this is trivial. In practice, it's difficult because the environment is precomputed. Each time an exported scalar is updated, its associated key value pair is updated in the precomputed environment. For exported named references, you would have to go through the whole parameter table each time a scalar is updated just to find whether there are exported named references that refer to it and update their associated key value pairs in the precomputed environment. That would be prohibitively expensive.
I would probably expect the result of the above code to be that the
environment contained ref=foo. Is that what you meant to type? I can't
see how the problem you describe would happen otherwise.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author