On Sat, Sep 28, 2024 at 14:53:10 +0100, Tim Woodall wrote:
> Is there a way in bash to guarantee that a trap gets called for cleanup
> in a script?

#!/bin/bash
trap cleanup EXIT
cleanup() {
    ...
}

This works in bash -- i.e., it calls the cleanup function regardless
of whether the shell exits by calling "exit", or by falling off the
end of the script, or by receiving a fatal signal.  It does NOT work in
/bin/sh (dash, or any other implementation).  You have been warned.

Reply via email to