On Sun, Jul 07, 2019 at 03:33:14PM +0200, Martijn Dekker wrote:
> On FreeBSD sh, when you set the export attribute on an otherwise unset
> variable, an empty environment variable is exported, though the variable
> continues to be considered unset within the current shell. This is the only
> shell I know of that does this.

> $ unset -v foo
> $ export foo
> $ echo ${foo+set}
> [empty line]
> $ sh -c 'echo ${foo+set}'
> set
> $ set | grep ^foo=
> $ env | grep ^foo=
> foo=

> Question: is this behaviour a bug in POSIX terms?

> As far as I can tell, the POSIX spec doesn't explicitly say what to do in
> this case:
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_22
> | The shell shall give the export attribute to the variables
> | corresponding to the specified names, which shall cause them to be in
> | the environment of subsequently executed commands.

> I could see how this phrasing technically requires the FreeBSD sh behaviour,
> but given that no other shell does this, it seems unlikely this requirement
> is intended. Could the text do with clarifying this?

As FreeBSD sh's maintainer, I decided that this behaviour is a bug and
changed it to be in line with other shells for FreeBSD 13.0:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=233545

Given that this has been broken for so long, all FreeBSD 11.x and 12.x
versions will not receive this fix (unless some circumstance makes it
crucial to have it).

-- 
Jilles Tjoelker

Reply via email to