#!/usr/bin/env bash die() { echo "$@" >&2 } command_failed() { die "command failed" } trap command_failed ERR set -E echo The trap should activate here.... epatch echo The trap should have activated above silly() { epatch [[ $(hostname) == [[:lower:]]* ]] } echo The trap should activate here.... silly echo The trap should have activated above echo The trap will /not/ activate here.... if silly; then echo "Your hostname starts with a lower-case letter!" else echo "You suck" fi echo The trap should not have activated above