trap-event

ERR

Run action on eligible failed commands and compound results, independently of errexit. Tested conditions suppress ERR; inheritance is controlled by errtrace.

Formal Syntax & Structure

bash syntaxbash
trap action ERR

Return Value

event

Run action on eligible failed commands and compound results, independently of errexit. Tested conditions suppress ERR; inheritance is controlled by errtrace.

Working Example

Example Snippetbash
trap 'rc=$?; printf "ERR=%s\n" "$rc" >&2' ERRfalseprintf 'still running\n'
Bash Reference