Is it possible to cancel a command via `DEBUG` trap WITHOUT enabling `extdebug`?
22:13 04 Mar 2026

In bash, the execution of any command can conditionally be cancelled via a DEBUG trap if shopt -s extdebug is enabled ( Cancel command in bash DEBUG trap ).

However, extdebug has many unwanted side effects which block me from permanently enabling the option (man bash):

extdebug

If set at shell invocation, or in a shell startup file, arrange to execute the debugger profile before the shell starts, identical to the --debugger option. If set after invocation, behavior intended for use by debuggers is enabled:

  1. The -F option to the declare builtin displays the source file name and line number corresponding to each function name supplied as an argument.

  2. If the command run by the DEBUG trap returns a non-zero value, the next command is skipped and not executed.

  3. If the command run by the DEBUG trap returns a value of 2, and the shell is executing in a subroutine (a shell function or a shell script executed by the . or source builtins), the shell simulates a call to return.

  4. BASH_ARGC and BASH_ARGV are updated as described in their descriptions above).

  5. Function tracing is enabled: command substitution, shell functions, and subshells invoked with ( command ) inherit the DEBUG and RETURN traps.

  6. Error tracing is enabled: command substitution, shell functions, and subshells invoked with ( command ) inherit the ERR trap.

Is it possible to cancel a command via DEBUG trap WITHOUT enabling extdebug?

bash