How can I achieve bash EXIT trap when exec-ing another binary?
问题 I'd like to use a bash EXIT trap and use exec to avoid spawning a new process. Is this possible? That is, #!/bin/bash touch $0.$$ trap "rm -v $0.$$" EXIT /bin/echo Hello removes the temporary file $0.$$ using bash's EXIT trap while #!/bin/bash touch $0.$$ trap "rm -v $0.$$" EXIT exec /bin/echo Hello never "fires" the trap (no message from rm , file $0.$$ exists after completion). It, of course, makes sense that the trap can't fire as bash is no longer in control after the exec . Is there some