foo1(){ echo hi-fail return 1}foo() { eai echo hi1 eai echo hi2 eai foo1 eai echo hi3}export -f foocleanup() { echo "Caught signal." echo.green "Cleaning up..." # By default with we seem to exit the script with non-zero status. # However, let's be explicit with that code you want to exit in case # of a clean up. # # exit 0 # exit 1}main() { trap cleanup SIGINT foo echo.yellow "Past foo (should not see this)"}main "${@}" && { echo.yellow "Exiting with success"} || { echo.yellow "Exiting with failure"}