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

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

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*
 *Aether Things Inc *
 *San Francisco*
  +1 (510) 388 1413

Reply via email to