trap-event
Bash trap PIPE
Normally associated with writing to a pipe that has no reader. A trap can report the event, but cannot restore a broken pipe. The fixture explicitly sends the signal; it does not reproduce an actual broken write. 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 PIPE; continued.
Formal Syntax & Structure
bash syntaxbash
trap 'handler' PIPEParameters & 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 PIPE\n'; }trap handler PIPE || exit 1kill -PIPE "$BASHPID" || exit 1printf 'continued\n'