How to untrap after a trap command

I have an error trap as follows:

trap failed ERR
function failed {
    local r=$?
    set +o errtrace
    set +o xtrace
    echo "###############################################"
    echo "ERROR: Failed to execute"
    echo "###############################################"
    # invokes cleanup
    cleanup
    exit $r
}

There is a part of my code where I do expect an error:

command1
command2
command3
set +e #deactivates error capture
command4_which_expects_error
set -e #re-activates error capture
command5

Overall I need to ignore the trap during the execution of command4_which_expects_error

The set +e does not seem to disable the trap. Any other ways to “untrap” and then “re-trap” ?


Source: bash

Leave a Reply