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 54463
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Issue with VAR=foo cmd where VAR is a named reference
- Date: Sun, 3 May 2026 12:05:35 -0700
- 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=IumtrshfxLTKVMKuu1mb4seXEIbfv/6nq9RbQtpaAgw=; fh=RngAOd9wlRc8Glv1v2GOfDUnq2FsyrczungEY8JNfXY=; b=d179NAp8MozLmuk2kwk1HIagzfKjHeSHxT9837Wz9wqU55mEFtquVAKhMupsDQm+iK TYmmHgROB+LRohfHvYpGP2FU11i5LBWPXOWSRLADoFx3e5tweCze/tT4DV3dH2rPxkp4 8QerdH+hoItaiB1V+nJLH3g4zb4uK03du6a4zHD14+NcvjCNs90ajX5SFJ1XsrMx+KWA 9yFJjbs4gpt1Kd1a+IEg2YSkbTb9xYprD4dGMCWdKbBz388kFrkoVJ2Htb/qGThAwLGR 5vA3FA5JNVpyyF+0hNFzbDdh1F17DXoJpT7tWBBhFJzC1Zu338rJsEwfzTrXnQYi/iJt H7RQ==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1777835147; cv=none; d=google.com; s=arc-20240605; b=AAbfVyQe2hYCkXwOXNvD6D2X1YTTeYszY6mSx+dLcyXU2BLANqNyMJPLkozPiSnrE1 fUZp0oYhb7qBxLiGlf3Uz+vA8nPXvk4wiu0/a5w7gtvxHV8mp0Buh8Z603DM1D9qbA6x YgUcHq3rryq0G12bLS8DQqHg4QZkPSS2P/0eyVmz0LcvR3v0F89CPwrileyK3tC5ATr6 I7cxof73DjBHpgDvYa6R5yaq60J7JWAgwIQ0MqOLZ3Xv/AV0PdFeaBMvAzOfdizXa0Mo FsABOe7ogxSP2Muo4N+IBpYlBGKT7QRNf2imILzw6m2ljsfDqgOaLrDXqn1SqtEhxMeT T5rw==
- Archived-at: <https://zsh.org/workers/54463>
- In-reply-to: <CAGdYchvh5Q+wG5au4=+-VDkZyvdu19-ac5gWsM-ZEGQm2_bgpw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchvh5Q+wG5au4=+-VDkZyvdu19-ac5gWsM-ZEGQm2_bgpw@mail.gmail.com>
On Sun, May 3, 2026 at 2:05 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> I think that the following is fine:
>
> % typeset -n VAR=var; VAR=foo typeset -p VAR var; typeset -p VAR var
> typeset -n VAR=var
> typeset var=foo
> zsh:typeset:1: no such variable: var
> typeset -n VAR=var
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.
> In other words, VAR=foo cmd, runs cmd with a parameter table where VAR's value has been temporarily changed to foo. If VAR happens to be a named reference, then it's the value of its referred variable that is changed.
I'm undecided about that. It could be argued that
VAR=foo command
should behave like
() { local -x VAR=foo; command }
That is, VAR in the environment is entirely distinct from VAR in the
calling shell. The difficult exception is the builtins that are
supposed to preserve assignment. I suppose ksh behavior would be
worthwhile to investigate.
> Note that it's impossible to export arrays (because the environment only supports string values). The following simply exports nothing:
>
> % ARR=(foo) printenv | grep ARR=
In that case you have
() { local -ax ARR=(foo); command }
so the no-array-exports rule kicks in.
> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author