Im working on error handling and logging in my bash script. Below I have included a simplified code snippet that exemplify the use case.
I want to achieve follow
You have to use
set -o pipefail
See this related StackOverflow Question.
Minimal example:
#!/bin/bash trap handler ERR handler() { echo trapped ; } echo 1 false | : echo 2 set -o pipefail false | :
Output:
$ bash test.sh 1 2 trapped