If a script is interrupted with the Interrupt key, it terminates and control is returned to the TC shell, that is, you get your prompt back. The onintr command is used to process interrupts within a script. It allows you to ignore the interrupt (^C) or transfer control to another part of the program before exiting. Normally, the interrupt command is used with a label to "clean up" before exiting. The onintr command without arguments restores the default action.
(The Script) 1 onintr finish 2 < Script continues here > 3 finish: 4 onintr - # Disable further interrupts 5 echo Cleaning temp files 6 rm $$tmp* ; exit 1 |
Explanation
The rest of the script lines are executed unless ^C (Interrupt key) is pressed while the program is in execution, at which time, control is transferred to the label.
This is the label; when the interrupt comes in, the program will continue to run, executing the statements below the label.
To shield this part of the script from interrupts, the onintr – is used. If Control-C is entered now, it will be ignored.
This line is echoed to the screen.
All tmp files are removed. The tmp files are prefixed with the shell's PID ($$) number and suffixed with any number of characters. The program exits with a status of 1.
18.119.253.31