0

When trapping a signal in bash, how could you then retrieve the signal which has been trapped?

For instance:

trap "cleanup;exit $SIGNAL" SIGINT SIGTERM

Such that the cleanup function is executed but the script still exits with its "correct" code.

Or is the signal not the correct exit code for an interrupted process?

pdm
  • 1,027
  • 1
  • 9
  • 24
  • 1
    http://stackoverflow.com/questions/2175647/is-it-possible-to-detect-which-trap-signal-in-bash/2175751#2175751 – Erik Jul 10 '14 at 20:47

1 Answers1

1

Is this what you are looking for?

trap "cleanup;exit 130" SIGINT
trap "cleanup;exit 143" SIGTERM

Signal is not the correct exit code for an interrupted process.

  • SIGINT: Signal 2 and exit code 130
  • SIGTERM: Signal 15 and exit code 143
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Ahh yes, actually that plus [this](http://tldp.org/LDP/abs/html/exitcodes.html) is exactly what I was looking for. Thank you! – pdm Jul 11 '14 at 20:39