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?

Thanks,

- M.

--
modernish -- harness the shell
https://github.com/modernish/modernish

Reply via email to