trap-event
Bash trap HUP
Often denotes terminal hangup; a service may define its own reload convention. A handler does not automatically implement reload or guarantee delivery. 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 HUP; continued.
Formal Syntax & Structure
bash syntaxbash
trap 'handler' HUPParameters & Attributes
| Name | Type | Description |
|---|---|---|
| handler | shell code | Trusted 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 HUP\n'; }trap handler HUP || exit 1kill -HUP "$BASHPID" || exit 1printf 'continued\n'