bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Consequences of shell errors


From: Nick Stoughton
Subject: Consequences of shell errors
Date: Wed, 17 Jun 2015 15:33:29 -0700

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

[Prev in Thread] Current Thread [Next in Thread]