Name
onintr
Synopsis
onintr label
onintr -
onintr
Description
“On interrupt.” Used in shell scripts to handle interrupt signals (similar to bash’s trap 2 and trap “” 2 commands). The first form is like a goto label. The script will branch to label: if it catches an interrupt signal (e.g., Ctrl-C). The second form lets the script ignore interrupts. This is useful at the beginning of a script or before any code segment that needs to run unhindered (e.g., when moving files). The third form restores interrupt handling that was previously disabled with onintr -.
Example
onintr cleanup
Go to "cleanup" on interrupt.
.
Shell script commands.
cleanup:
Label for interruptsonintr -
Ignore additional interruptsrm -f $tmpfiles
Remove any files createdexit 2
Exit with an error status
Get Linux in a Nutshell, Third Edition 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.