Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

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



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

Oh yes, you are right! Stupid me copied the wrong thing. Here is what I meant: 

% typeset var=foo
% typeset -nx ref=var
% printenv | grep ref=
ref=foo
% zsh -c 'typeset -p ref'
export ref=foo

Philippe



Messages sorted by: Reverse Date, Date, Thread, Author