trap-event

Bash trap QUIT

A quit request, often from a terminal. Bash normally ignores SIGQUIT; a noninteractive shell can install a trap when the signal was not ignored on entry. The fixture is a direct signal, not a terminal keypress. This fixture sends the signal only to its own disposable Bash process using BASHPID. The handler returns, allowing the script to continue. Signals ignored on shell entry may not be trappable in noninteractive Bash. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): handled QUIT; continued.

Formal Syntax & Structure

bash syntaxbash
trap 'handler' QUIT

Parameters & Attributes

NameTypeDescription
handlershell codeTrusted code executed on delivery.

Return Value

exit status

trap reports registration status; handler execution and subsequent command status are distinct.

Working Example

Example Snippetbash
handler() { printf 'handled QUIT\n'; }trap handler QUIT || exit 1kill -QUIT "$BASHPID" || exit 1printf 'continued\n'
Bash Reference