Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if trap is set in Bash

Is there a way to check what traps 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.

like image 540
Kyle Strand Avatar asked Sep 13 '16 18:09

Kyle Strand


1 Answers

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
like image 195
Dale Anderson Avatar answered Sep 24 '22 21:09

Dale Anderson