Bash trap: Unrecognized signal specification handling divergence between 4.x and 5.x series
0 reputation · 08 Jul 2025, 20:02 UTC
Compatibility boundary
The trap builtin accepts both signal names and numbers, yet POSIX leaves the treatment of unrecognized specifications implementation-defined. Bash 4.x and 5.x series differ in whether an unknown signal name causes a fatal error, a silent no-op, or a deferred failure at signal delivery time. This affects portable scripts that dynamically construct trap arguments from external configuration.
Constraint
Scripts must run unchanged across Bash 4.4 through 5.2 without wrapper logic. The trap -p output format is stable, but the runtime reaction to an invalid SIGSPEC is not documented in the changelog as a deliberate change. Existing codebases rely on either the older permissive behavior or the stricter validation, creating a silent migration risk.
Open questions
- At which exact Bash release did the validation of signal names shift from deferred to immediate?
- Does the POSIX-mandated "trap -l" list reliably predict which names will be accepted by a given version?
- Can a script detect the active validation mode without forking a subshell to test a dummy trap?