trap - Trap signals

Synopsis

trap [ action condition ... ]

trap -p [ condition ... ]

trap -l

Description

The trap utility sets the action for qsh to take when a condition arises. qsh expands action once when running trap and again when condition arises.

When the -p option is specified, trap displays the current action for the specified conditions.

When the -l option is specified, trap displays a list of all of the signal names and their corresponding numbers.

When no arguments are specified, trap displays a list of the currently defined traps.

Options

-l
Display a list of all of the signal names and their corresponding numbers.
-p
Display each trap in a re-enterable format.

Operands

For action, you can specify:

For condition, you can specify:

If more than one condition arises at the same time, qsh runs the traps in this order:

  1. DEBUG, if it is specified, then
  2. ERR, if it is specified and applicable, then
  3. Any other specified traps in signal number order, then
  4. EXIT.

Exit Status

Related information

Examples
  1. Set a trap for the ERR condition:
    trap `print Command failed' ERR
    
  2. Ignore the ERR condition:
    trap "" ERR
    
  3. Reset the ERR condition to its original value:
    trap - ERR
    
  4. Display the current action for the ERR condition:
    trap -p ERR
    
  5. Display all of the currently defined traps:
    trap