trap

Official Description

Traps a signal to be serviced by a signal handler.

Syntax

trap [argument][signal ...] | [-p]

Options

-p prints the currently trapped signals.

Oddities

If the argument is omitted or is -, all traps associated with signals are reset to their original values.

Example

$ trap –p                    # No signals being trapped yet
$
$ trap 'print "Trapped"' INT QUIT # Trap INT (CTRL+C) and QUIT (CTRL+\)
$
$ trap –p                    # Print signals being trapped
trap -- 'print "Trapped"' QUIT
trap -- 'print "Trapped"' INT
$
$ Trapped                   # CTRL+C
$
$ Trapped                   # CTRL+\
$
$ trap - INT QUIT            # Back to default trapping
$
$ trap –p                    # No more special traps
$
				

Get Korn Shell Programming 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.