The trap command allows you to trap incoming signals to your scripts. The format of the trap command is:
trap name signal(s)
The name is a list of instructions to be performed when the signal is caught. In reality a function should be called that deals specifically with trapped signals. The name should be surrounded by double quotes (" "). The signal(s) are the incoming signals.
When a signal is trapped a script will generally be in the middle of some processing. The most common form of action to take is:
Clean up temporary files.
Ignore the signals.
Ask the user if the script is really to be terminated.
Here’s a table of the most common trap usages:
|trap " " 2 3||Ignore the signals 2 and 3; user cannot terminate|