Reputation: 16529
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.
Upvotes: 9
Views: 4254
Reputation: 140307
Let's define a function as follows:
$ function f
> {
> echo trapped
> }
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
Upvotes: 7
Reputation: 2460
Yes.
You can either see all traps, or traps for a specific signal:
$ trap # show all traps for all signals
$ trap -p SIGINT # only show traps for SIGINT
$ trap -p EXIT # only show traps for EXIT
Upvotes: 10