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 builtin trap. If you wanna see the docs for any of the non-fish versions, use command 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 like INT or SIGINT, or the special symbol EXIT. πŸ’–

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 🧚

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