TRAP(1)
π
TRAP(1) β the fish-shell girlies' guide to trap
ok so first things first, bestie: this is the fish-shell manual page (like, the fish version specifically), and we're talking about trap β¨
π NAME π
trap β do a whole action when the shell gets a signal, slay
πΈ SYNOPSIS πΈ
trap [OPTIONS] [[ARG] REASON ... ]
β¨ DESCRIPTION β¨
β οΈ NOTE: this page documents the fish builtintrap. If you wanna see the docs for any of the non-fish versions, usecommand man trap. iykyk π
ok so trap is literally just 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 event handler (check the event handler section, it's right there).
the way these parameters work:
ARGβ the command to be executed on signal delivery. like, what actually runs. πREASONβ the name of the event to trap. for example, a signal likeINTorSIGINT, or the special symbolEXIT. π
and the options, periodt:
-l,--list-signalsβ prints a list of signal names. a little menu of vibes β¨-p,--printβ prints all defined signal handlers.-h,--helpβ displays help about using this command. π«Ά
ok now the actual behaviour, pay attention bestie π
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).
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). like, back to factory settings π
if ARG is the null string, the signal specified by each REASON is ignored by the shell and by the commands it invokes. not me just ignoring the signal π
if ARG is not present and -p has been supplied, then the trap commands associated with each REASON are displayed. and if no arguments are supplied, or if only -p is given, trap prints the list of commands associated with each signal. π
signal names are case insensitive and the SIG prefix is optional. highkey convenient. and β important β trapping a signal will prevent fish from exiting in response to that signal. π₯
the exit status is 1 if any REASON is invalid; otherwise trap returns 0. π¦
π EXAMPLE π
trap "status --print-stack-trace" SIGUSR1
# Prints a stack trace each time the SIGUSR1 signal is sent to the shell.
literally iconic. it prints a stack trace every single time SIGUSR1 gets sent to the shell π§
π Copyright π
fish-shell developers β credits to the icons who made it π«Ά
ok that's the whole page, bestie! this was version 4.9, dated Sep 08, 2026, straight from fish-shell. no cap, you're a trap expert now π
β¨π
π¦ where this page comes from
- arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms