1. After the trap captures the signal, there are three response methods:
(1) execute a program to process this signal.
(2) default operation for receiving signals
(3) Ignore this signal
Ii. trap provides three basic forms for the above three methods:
The first form of trap Command will execute the command string in double quotation marks when shell receives signals with the same values in the signal list.
Trap 'commands' signal-list
Trap "commands" signal-list
To restore the default signal, use the second form of trap command:
Trap signal-list
The third form of trap command allows ignoring Signals
Trap "" signal-list
Note:
(1) The signal 11 (segment violation) cannot be captured, because the shell itself needs to capture the signal for memory dump.
(2) In the trap, you can define the processing of the signal 0 (in fact, there is no such signal). The shell program sends this signal when it terminates (such as executing the exit Statement.
(3) After capturing the signal specified in the signal-list and executing the corresponding commands, if these commands do not terminate the shell program, the shell program will continue to execute the command after the command received when the signal is received, which will easily cause the shell program to be unable to terminate.
In the trap statement, single quotes and double quotation marks are different. When the shell program first encounters a trap statement, it will scan the commands in commands. If commands is enclosed in single quotes, shell will not replace the variables and commands in commands. Otherwise, the variables and commands in commands will be replaced with the specific values at that time.