2006-01-23 23:17:06 +00:00
\section trap trap - perform an action when the shell receives a signal
2005-12-17 21:30:52 +00:00
\subsection trap-synopsis Synopsis
2014-08-01 12:25:41 +00:00
\fish{synopsis}
2014-08-01 02:37:32 +00:00
trap [OPTIONS] [[ARG] SIGSPEC ... ]
\endfish
2005-12-17 21:30:52 +00:00
\subsection trap-description Description
2014-08-19 12:41:23 +00: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-17 21:30:52 +00: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 07:56:01 +00:00
The following parameters are available:
2005-12-17 21:30:52 +00:00
2014-08-01 02:37:32 +00:00
- `ARG` is the command to be executed on signal delivery.
2014-08-19 12:41:23 +00:00
2014-08-01 02:37:32 +00:00
- `SIGSPEC` is the name of the signal to trap.
2014-08-19 12:41:23 +00:00
2014-08-01 02:37:32 +00:00
- `-l` or `--list-signals` prints a list of signal names.
2014-08-19 12:41:23 +00:00
2014-08-01 02:37:32 +00:00
- `-p` or `--print` prints all defined signal handlers.
2005-12-17 21:30:52 +00:00
2014-08-19 12:41:23 +00:00
If `ARG` and `SIGSPEC` are both specified, `ARG` is the command to be executed when the signal specified by `SIGSPEC` 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 07:56:01 +00:00
2014-08-19 12:41:23 +00:00
If `ARG` is absent (and there is a single SIGSPEC) 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 `SIGSPEC` is ignored by the shell and by the commands it invokes.
2005-12-17 21:30:52 +00:00
2014-08-19 12:41:23 +00:00
If `ARG` is not present and `-p` has been supplied, then the trap commands associated with each `SIGSPEC` 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-17 21:30:52 +00:00
2014-08-01 02:37:32 +00:00
Signal names are case insensitive and the `SIG` prefix is optional.
2005-12-17 21:30:52 +00:00
2014-08-19 12:41:23 +00:00
The return status is 1 if any `SIGSPEC` 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 07:56:01 +00:00
\subsection trap-example Example
2014-08-19 12:41:23 +00:00
2014-08-08 02:44:37 +00:00
\fish
trap "status --print-stack-trace" SIGUSR1
# Prints a stack trace each time the SIGUSR1 signal is sent to the shell.
\endfish