Date:        Sun, 16 Jan 2022 20:26:00 +0000
    From:        "Martijn Dekker via austin-group-l at The Open Group" 
    Message-ID:  <>

  | I need some clarity. Should ${var:=value} and ${var=value} honour 
  | allexport?


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:]

      including variables that are assigned a value by the
      getopts, read, or cd utilities,

[those things are not variable assignments within the meaning of XBD 4.23]

      shall cause that variable to gain the export attribute.

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.

Another case worth checking is unset var; set -a; echo $(( var=3 ));
and verify that after that, var is exported ($SHELL -c 'echo $var').

It might be worth appending to the "including variables..." clause
    and also including side effects of parameter and arithmetic expansions,

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).
IMO it should, it is absurd that (in many shells) and given

        unset var

as a precondition, that

        : ${var=value}

can result in different final settings for "var" (ie: "${var}" will
often expand differently).

Since the latter is a very frequently used shorthand for

        if [ -z "${var+set}" ]; then var=value; fi

I believe it would be a very good idea to ensure that those two
forms produce identical results.

The standard cannot really require this at the minute, as too many
shells don't expand the "value" word the same way in the simple
assignment and the word expansion assignment - but it can make it
clear that either is acceptable, and recommend that they be expanded
the same way (while cautioning users that it is not currently guaranteed).
A "future directions" would be good too.

Implementors should really be making the two equivalent, regardless of
what the standard says, as anything else is simply incomprehensible to
the average user.


  • Re: what variables a... Martijn Dekker via austin-group-l at The Open Group
    • Re: what variab... Robert Elz via austin-group-l at The Open Group
    • Re: what variab... via austin-group-l at The Open Group

Reply via email to