Issue with VAR=foo cmd where VAR is a named reference

Philippe Altherr <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAGdYchvh5Q+wG5au4=+-VDkZyvdu19-ac5gWsM-ZEGQm2_bgpw@mail.gmail.com>
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

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.

On the other hand, the following looks wrong:

% typeset -n VAR=var; VAR=foo printenv | grep -i VAR=
var=foo

My expectation is that running VAR=foo cmd, runs cmd in an environment
augmented with the key value pair VAR=foo. Exporting named references is
currently not possible. Therefore the example above should in my
opinion not export anything. There is no reason for it to export the
referred variable.

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=

The same should happen for named references, at least as long as exporting
them isn't supported.

Exporting named references is in principle possible but doing so requires
additional infrastructure in the code and/or may significantly impact
performance. If desired it could be achieved but I don't think it's a high
priority.

Philippe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.