Op 17-01-22 om 22:54 schreef Robert Elz:
Date: Sun, 16 Jan 2022 20:26:00 +0000
From: "Martijn Dekker via austin-group-l at The Open Group"
<[email protected]>
Message-ID: <[email protected]>
| I need some clarity. Should ${var:=value} and ${var=value} honour
| allexport?
Yes.
Any assignment (in the usual sense of that word) to a variable while -a is
in effect should result in the variable being exported, no matter how
it is accomplished. Further in draft 2.1 it actually says:
When this option is on, a variable that is assigned a value
(see XBD Section 4.23),
[that xref is prehaps unfortunate, it really is not needed here as:]
Yes, that xref is the whole cause of the issue. On ksh, the bug appears
to be historic behaviour inherited from the Bourne shell, but the xref
appears to have mislead the author of the newer shell yash, which
replicated the bug.
But the fact that they're included makes it clear that any assignment
to a variable counts (even the absurd _ variable, which fortunately
is not posix, but is supported by ksh versions, and to varying extents
by most other shells). Assignments performed as a side effect of
word expansions are certainly included.
Then the standard should say that.
Another case worth checking is unset var; set -a; echo $(( var=3 ));
and verify that after that, var is exported ($SHELL -c 'echo $var').
Good point.
The situation with arithmetic assignment seems to be the same: ksh93,
pdksh/mksh, and yash do not export the variable.
It might be worth appending to the "including variables..." clause
above:
and also including side effects of parameter and arithmetic expansions,
Yes.
What follows has nothing to do with -a, but another aspect of ${var=value}
What is less clear about ${var=value} (and the form with the : as
well of course) is whether the assignemnt, when it is performed, ought
to be considered as a XBD 4.23 type variable assignment, with everything
that comes with that (including the rules for how tilde expansion happens).
As far as I can tell, there is currently nothing to indicate that it should.
--
|| modernish -- harness the shell
|| https://github.com/modernish/modernish
||
|| KornShell lives!
|| https://github.com/ksh93/ksh