When I use the trap
command in bash, the previous trap
for the given signal is replaced.
Is there a way of making more than one trap<
I add a slightly more robust version of Laurent Simon's trap-add
script:
'
characterssed
instead of bash pattern substitution, but that would make it significantly slower.trap-add () {
local handler=$(trap -p "$2")
handler=${handler/trap -- \'/} # /- Strip `trap '...' SIGNAL` -> ...
handler=${handler%\'*} # \-
handler=${handler//\'\\\'\'/\'} # <- Unquote quoted quotes ('\'')
trap "${handler} $1;" "$2"
}