Catch Trap Interrupt
foo1(){
echo hi-fail
return 1
}
foo() {
eai echo hi1
eai echo hi2
eai foo1
eai echo hi3
}
export -f foo
cleanup() {
echo "Caught signal."
echo.green "Cleaning up..."
}
main() {
trap cleanup SIGINT
foo
echo.yellow "Past foo (should not see this)"
}
main "${@}" && {
echo.yellow "Exiting with success"
} || {
echo.yellow "Exiting with failure"
}
mac> ${SCRATCH_SHELL} && echo ZERO_EXIT || echo NON_ZERO_EXIT
> echo hi1 (ROOT_PID:26333, BASHPID:26333)
hi1
Successfully completed: [echo hi1] (ROOT_PID:26333, BASHPID:26333)
> echo hi2 (ROOT_PID:26333, BASHPID:26333)
hi2
Successfully completed: [echo hi2] (ROOT_PID:26333, BASHPID:26333)
> foo1 (ROOT_PID:26333, BASHPID:26333)
hi-fail
Failed to execute: [foo1] (ROOT_PID:26333, BASHPID:26333)
Interrupting: Failed to execute [foo1]
FunctionChain: (main:34-->main:29-->foo:9-->eai:0-->execute_announce_or_interrupt:0-->throw:0-->interrupt)
PWD: /usr/local/workplace/thorg-root
PID : 26333
BASHPID: 26333
Caught signal.
Cleaning up...
NON_ZERO_EXIT