On Wed, 2024-02-28 at 00:56 +0000, Harald van Dijk wrote: > 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 As far as I can see, POSIX doesn't seem to be absolutely definite about this, but personally I'd say the spirit of it is rather that set -a generally applies, and so foo would be exported. One might also argue like this: * -a says "the export attribute shall be set for each variable to which an assignment is performed". * readonly does assign at some point before it returns and at that point, the variable obviously cannot be readonly already. Only before it returns it's made readonly. Since -a acts already at the assignment step, it the export is set before the readonly. But of course, that's also a lot of reading something into it ;-) Cheers, Chris.