2006-01-24 07:17:06 +08:00
\section trap trap - perform an action when the shell receives a signal
2005-12-18 05:30:52 +08:00
\subsection trap-synopsis Synopsis
2014-08-01 20:25:41 +08:00
\fish{synopsis}
2017-03-15 12:02:02 +08:00
trap [OPTIONS] [[ARG] REASON ... ]
2014-08-01 10:37:32 +08:00
\endfish
2005-12-18 05:30:52 +08:00
\subsection trap-description Description
2014-08-19 20:41:23 +08:00
`trap` is a wrapper around the fish event delivery framework. It exists for backwards compatibility with POSIX shells. For other uses, it is recommended to define an <a href='index.html#event'>event handler</a>.
2005-12-18 05:30:52 +08:00
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 15:56:01 +08:00
The following parameters are available:
2005-12-18 05:30:52 +08:00
2014-08-01 10:37:32 +08:00
- `ARG` is the command to be executed on signal delivery.
2014-08-19 20:41:23 +08:00
2017-03-15 12:02:02 +08:00
- `REASON` is the name of the event to trap. For example, a signal like `INT` or `SIGINT`, or the special symbol `EXIT`.
2014-08-19 20:41:23 +08:00
2014-08-01 10:37:32 +08:00
- `-l` or `--list-signals` prints a list of signal names.
2014-08-19 20:41:23 +08:00
2014-08-01 10:37:32 +08:00
- `-p` or `--print` prints all defined signal handlers.
2005-12-18 05:30:52 +08:00
2017-03-15 12:02:02 +08:00
If `ARG` and `REASON` are both specified, `ARG` is the command to be executed when the event specified by `REASON` occurs (e.g., the signal is delivered).
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 15:56:01 +08:00
2017-03-15 12:02:02 +08:00
If `ARG` is absent (and there is a single REASON) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If `ARG` is the null string the signal specified by each `REASON` is ignored by the shell and by the commands it invokes.
2005-12-18 05:30:52 +08:00
2017-03-15 12:02:02 +08:00
If `ARG` is not present and `-p` has been supplied, then the trap commands associated with each `REASON` are displayed. If no arguments are supplied or if only `-p` is given, `trap` prints the list of commands associated with each signal.
2005-12-18 05:30:52 +08:00
2014-08-01 10:37:32 +08:00
Signal names are case insensitive and the `SIG` prefix is optional.
2005-12-18 05:30:52 +08:00
2017-03-15 12:02:02 +08:00
The return status is 1 if any `REASON` is invalid; otherwise trap returns 0.
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 15:56:01 +08:00
\subsection trap-example Example
2014-08-19 20:41:23 +08:00
2014-08-08 10:44:37 +08:00
\fish
trap "status --print-stack-trace" SIGUSR1
# Prints a stack trace each time the SIGUSR1 signal is sent to the shell.
2017-03-15 12:02:02 +08:00
\endfish