Skip to content

Instantly share code, notes, and snippets.

@jotafeldmann
Last active February 17, 2017 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jotafeldmann/804d99f88b15d95effb5d984332976fe to your computer and use it in GitHub Desktop.
Save jotafeldmann/804d99f88b15d95effb5d984332976fe to your computer and use it in GitHub Desktop.
How to get EXIT SIGNAL in bash for TRAPS
#!/bin/bash
trap_with_arg() {
func="$1" ; shift
for sig ; do
trap "$func $sig" "$sig"
done
}
func_trap() {
echo Trapped: $1
}
trap_with_arg func_trap SIGHUP SIGINT SIGQUIT SIGILL SIGTRAP SIGABRT SIGEMT SIGFPE SIGKILL SIGBUS SIGSEGV SIGSYS SIGPIPE SIGALRM SIGTERM SIGURG SIGSTOP SIGTSTP SIGCONT SIGCHLD SIGTTIN SIGTTOU SIGIO SIGXCPU SIGXFSZ SIGVTALRM SIGPROF SIGWINCH SIGINFO SIGUSR1 SIGUSR2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment