Table 1.1 taken from [6, p. 883] shows some of the signals used in Shell Programming.
The trap command typically appears as one of the first lines in the shell script. It contains the commands to be executed when a signal is detected as well as what signals to trap.
#!/bin/sh TMPFILE=/usr/tmp/junk.$$ trap 'rm -f $TMPFILE; exit 0' 1 2 15 . . .
Upon receiving signals 1, 2 or 15, $TMPFILE would be deleted and the script would terminate the shell script normally. This shows how trap may be used to clean up before exiting.
#!/bin/sh TMPFILE=/usr/tmp/junk.$$ trap '' 0 1 2 . . .
The above example shows how trap may be used to ignore specific signals (0, 1 and 2), while NOT interrupting the current line of execution.
NOTE that when the signal is received, the command currently being executed is interrupted (except in the case where there is nothing to be executed between the two quotation signs), and execution flow continues at the next line of the script.