O'Reilly logo

Linux in a Nutshell, Fourth Edition by Aaron Weber, Stephen Figgins, Ellen Siever

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

onintr

Synopsis

                  onintr 
                  label
                  onintr -
onintr
               

“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 previously disabled with onintr -.

Example

                  onintr cleanup     
                  Go to "cleanup" on interrupt
                   .
                   .                 
                  Shell script commands
                   .
                  cleanup:           
                  Label for interrupts
                  onintr -         
                  Ignore additional interrupts
                  rm -f $tmpfiles  
                  Remove any files created
                  exit 2           
                  Exit with an error status

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required