Let's say I have the following trap, which catches some signals, which terminate the script:
#!/bin/sh
trapterm() {
echo "Process (PID: $$) interrupted." >&2
exit 2
}
# add trap to catch terminating signals
trap trapterm INT TERM
# […]
Now, how can I get the signal, which caused the trap being called, and output it? The result should work like this fictitious $SIGNAL
:
#!/bin/sh
trapterm() {
echo "Process (PID: $$) interrupted by signal $SIGNAL." >&2
exit 2
}
# add trap to catch terminating signals
trap trapterm INT TERM
# […]
Shell-specific solutions (bash) are okay, but I'd prefer a POSIX-compatible ones.