trap-event

Bash trap USR1

Application-defined signal. Establish a documented handler contract; no standard reload or diagnostic action is implied. 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 USR1; continued.

Formal Syntax & Structure

bash syntaxbash
trap 'handler' USR1

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 USR1\n'; }trap handler USR1 || exit 1kill -USR1 "$BASHPID" || exit 1printf 'continued\n'
Bash Reference