trap

NAME

trap - sets trap handler

SYNOPSIS

trap [handler signal ...]

DESCRIPTION

This command is a Korn-shell built-in command.

The trap(1) command sets a trap handler that is to be executed when any of the specified signals are received. The handler argument is either a null string, indicating the signals are to be ignored; a minus (-), indicating that the default action is to be taken for the signals (see signal(2)); or a string containing shell commands to be evaluated and executed at the first opportunity (that is, when the current command completes, or before printing the next PS1 prompt) after receipt of one of the signals. The signal argument is the name of a signal (for example, PIPE or ALRM) or the number of the signal (see the kill -l command). There are two special signals: EXIT (also known as 0), which is executed when the shell is about to exit, and ERR which is executed after an error occurs (an error is something that would cause the shell to exit if the -e or errexit option were set — see set(1) command). EXIT handlers are executed in the environment of the last executed command. Note that for noninteractive shells, the trap handler cannot be changed for signals that were ignored when the shell started.

With no arguments, trap lists, as a series of trap commands, the current state of the traps that have been set since the shell started.

The original Korn shell's DEBUG trap and the handling of ERR and EXIT traps in functions are not yet implemented.