Send stderr/stdout messages to function and trap exit signal Send stderr/stdout messages to function and trap exit signal unix unix

Send stderr/stdout messages to function and trap exit signal


You have to use

set -o pipefail

See this related StackOverflow Question.


Minimal example:

#!/bin/bashtrap handler ERRhandler() { echo trapped ; }echo 1false | :echo 2set -o pipefailfalse | :

Output:

$ bash test.sh12trapped