set -e
X=$(false)
# should not reach here
export X
echo did not exit
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.
"An expansion error is one that occurs when the shell expansions defined in Section 2.6 are
carried out" ... and section 2.6 includes command substitution.
But every shell I tested behaves the same way (sh, bash, dash, ksh, mksh, yash and zsh), so I feel I must be missing something. Can someone explain why the first 2 examples do not exit on the error in the expansion?
______________________________
Nick Stoughton