Without arguments trap
prints the currently set commands for all traps. However, a subshell does not inherit traps, so the canonical example for saving and restoring traps fails in bash:
save_traps=$(trap) ... eval "$save_traps"
The trap on the RHS of the assignment runs in a subshell, so save_traps is always the empty string. Other than writing the output of trap
to a temporary file, how can a script find the current command set for a trap?