Handling INTERRUPTS in shell scripts
The C shell provides a mechanism for trapping interrupts generated by
Control-C with the onintr statement.
There are three forms:
onintr label # go to label on interrupt
ontinr - # ignore all interrupts
onintr # restore interrupts to default
An example shell script:
-------------------------
#!/bin/csh -f
onintr int
echo "trapping interrupt for ls -l"
ls -l
echo "Interrupts disabled during ls -la"
onintr -
ls -la
echo "Business as usual for ls -lag"
onintr
ls -lag
exit 0 # Program finishes here.
int:
echo "ls -l interrupted"
exit 1
-------------------------
Try breaking at each phase of the script and see how onintr works.
Interrupt trapping is useful when you must unlock a file before exiting, and
interrupt disabling is useful when copying, moving, or writing files.
|