Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
On 6/17/15 6:33 PM, Nick Stoughton wrote:
> I was surprised when the following script did NOT exit at the indicated line:
>
> set -e
> export X=$(false)
> # should not reach here
> echo did not exit
>
> Similarly, this fails in the same way:
>
> set -e
> X=$(false) export X
> # should not reach here
> echo did not exit
Neither of these are failures; the export command returns success. In
fact, according to Posix, the export command cannot fail.
> while, conversely, this did exit as expected and exited on error:
> *
> *
> set -e
> X=$(false)
> # should not reach here
> export X
> echo did not exit
Because
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01
calls it out as a special case.
> The export utility is a special built-in, and according to POSIX XCU 2.8.1
> "Consequences of Shell Errors", special built-ins should exit (with a
> diagnostic message) on both variable assignment error and expansion error.
This is neither a variable assignment error (the variable is correctly
assigned the output of the command substitution) nor an expansion error
(the command substitution is well-formed).
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/