builtin
trap
Register, inspect or reset fixed actions for signals or Bash pseudo-events. An empty action ignores a signal, a dash restores its default; KILL and STOP cannot be caught. Quote the action for evaluation at event time.
Formal Syntax & Structure
bash syntaxbash
trap [-lp] [[action] event ...]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| action | shell code | Trusted action or reset marker. |
| event | signal or pseudo-event | Signal name/number or supported pseudo-event. |
Return Value
exit status
Register, inspect or reset fixed actions for signals or Bash pseudo-events. An empty action ignores a signal, a dash restores its default; KILL and STOP cannot be caught. Quote the action for evaluation at event time.
Working Example
Example Snippetbash
bash -c ' on_int() { printf "INT\n"; exit 130; } trap on_int INT kill -INT "$$" printf "unreachable\n"'printf 'child=%s\n' "$?"