It seems on_error
trap in Bash works only in the scope of function it was defined in. For instance running this script
#!/bin/bash
on_error() {
echo 'on_error'
}
f() {
false
echo 'function f'
}
g() {
trap on_error ERR
echo 'function g'
false
f
}
g
produces:
function g
on_error
function f
Is there a way to trap on_error
globally so that I don't have to trap it in each function separately?