Skip to content Accesskey=4Skip to sub-navigation Accesskey=3View our Accessibility Options MIT Information Systems Home About IS&T Contact IS&T Site Map Search Advanced Search
Getting StartedGetting Services by Topic or Alphabetically Getting Help

On This Page

[Help]

  

Quick Links

Top Level

Related Links

Ask OLC a question

Athena Consulting Homepage

Helpdesk Stock Answers (for Mac/PC questions)


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.

MIT Home | Getting Started | Getting Services | Getting Help | About IS&T | Accessibility
Ask a technology question or send a comment about this web page.