Why doesn’t bash flag -e exit when a subshell fails?

It appears as though this is related to your version of bash. On machines that I have access to, bash version 3.1.17 and 3.2.39 exhibit this behaviour, bash 4.1.5 does not.

Although a bit ugly, a solution that works in both versions could be something like this:

#!/bin/bash -e

(false) || exit $?

echo $?
echo "Line reached!"

There are some notes in the bash source changelog which related to bugs with the set -e option.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)