Kyle Strand Kyle Strand - 2 months ago 6
Bash Question

Check if trap is set in Bash

Is there a way to check what

trap
s have been set (in the current session or script) in Bash?

Ideally, I'd like to be able to get a list of the signals that have a
trap
assigned to them, but if that's not possible I can just check each signal individually.

Answer

Let's define a function as follows:

$ function f
> {
> echo flfllf
> }

Let's set the trap to that function assigned to SIGINT

$ trap f SIGINT

Let's list set traps:

$ trap
trap -- 'f' SIGINT
trap -- '' SIGTSTP
trap -- '' SIGTTIN
trap -- '' SIGTTOU
Comments