Op 29-02-2024 om 18:07 schreef Harald van Dijk:
On 29/02/2024 17:41, Martijn Dekker wrote:
Op 28-02-2024 om 00:56 schreef Harald van Dijk:
However, trying to fix this I come across a corner case where it is not
clear to me what the intended behaviour is.
set -a; readonly foo=bar; export # some shells export, not all
IMO, the shell should export it in that case; POSIXly, 'set -a' should cause
the variable to be exported whenever a value is effectively assigned to it
(whether this is by a "true" shell assignment, an assignment-argument, an
expansion like ${foo=bar} or ${foo:=bar}, indirectly by 'read' or 'getopts',
or maybe other cases I'm not thinking of).
Spec-wise, the thing that troubles me is that the option is specified as
> When this option is on, the export attribute shall be set for each
> variable to which an assignment is performed; see XBD Variable
> Assignment.
where XBD Variable Assignment is only about the assignment syntax of the
shell, not other syntax or other commands even if they also cause variables to
become assigned.
Yeah, that's confusing (and IMO should be fixed in the spec), but that same
paragraph goes on to mention 'getopts' and 'read' as examples of utilities
that perform assignments. In other words, though 'read var' is no XBD
"Variable Assignment" assignment, it's stated explicitly that 'var', on which
'read' performs an assignment, should gain the export attribute.
--
|| modernish -- harness the shell
|| https://github.com/modernish/modernish
||
|| KornShell lives!
|| https://github.com/ksh93/ksh