Re: wrong behaviour when unsetting/setting some variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

That said, I think I agree that this just does not make sense, and even if the spec says this, it is not what current versions of shells including bash and dash do, so even if my reading of the spec is correct, that makes it a spec bug, not a shell bug, and dash should not change behaviour here. (Of course, the originally reported bug should still be fixed.)

Cheers,
Harald van Dijk




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux