.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "TRAP" "1" "Nov 13, 2025" "4.2" "fish-shell" .SH NAME trap \- perform an action when the shell receives a signal .SH SYNOPSIS .nf \fBtrap\fP [\fIOPTIONS\fP] [[\fIARG\fP] \fIREASON\fP \&...\fB ]\fP .fi .sp .SH DESCRIPTION .sp NOTE: This page documents the fish builtin \fBtrap\fP\&. To see the documentation on any non\-fish versions, use \fBcommand man trap\fP\&. .sp \fBtrap\fP 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 \fI\%event handler\fP\&. .sp The following parameters are available: .INDENT 0.0 .TP .B \fIARG\fP Command to be executed on signal delivery. .TP .B \fIREASON\fP Name of the event to trap. For example, a signal like \fBINT\fP or \fBSIGINT\fP, or the special symbol \fBEXIT\fP\&. .TP \fB\-l\fP or \fB\-\-list\-signals\fP Prints a list of signal names. .TP \fB\-p\fP or \fB\-\-print\fP Prints all defined signal handlers. .TP \fB\-h\fP or \fB\-\-help\fP Displays help about using this command. .UNINDENT .sp If \fIARG\fP and \fIREASON\fP are both specified, \fIARG\fP is the command to be executed when the event specified by \fIREASON\fP occurs (e.g., the signal is delivered). .sp If \fIARG\fP is absent (and there is a single \fIREASON\fP) or \fB\-\fP, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If \fIARG\fP is the null string the signal specified by each \fIREASON\fP is ignored by the shell and by the commands it invokes. .sp If \fIARG\fP is not present and \fB\-p\fP has been supplied, then the trap commands associated with each \fIREASON\fP are displayed. If no arguments are supplied or if only \fB\-p\fP is given, \fBtrap\fP prints the list of commands associated with each signal. .sp Signal names are case insensitive and the \fBSIG\fP prefix is optional. Trapping a signal will prevent fish from exiting in response to that signal. .sp The exit status is 1 if any \fIREASON\fP is invalid; otherwise trap returns 0. .SH EXAMPLE .INDENT 0.0 .INDENT 3.5 .sp .EX trap \(dqstatus \-\-print\-stack\-trace\(dq SIGUSR1 # Prints a stack trace each time the SIGUSR1 signal is sent to the shell. .EE .UNINDENT .UNINDENT .SH COPYRIGHT fish-shell developers .\" Generated by docutils manpage writer. .