11.8. Interrupt Handling

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.

Example 11.46.
(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

  1. The onintr command is followed by a label name. The label finish is a user-defined ...

Get Linux Shells by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.