How to trap ERR when using ‘set -e’ in Bash
chepner’s answer is the best solution: If you want to combine set -e (same as: set -o errexit) with an ERR trap, also use set -o errtrace (same as: set -E). In short: use set -eE in lieu of just set -e: #!/bin/bash set -eE # same as: `set -o errexit -o errtrace` trap ‘echo … Read more