EXIT trap

A trap on the special name EXIT, whose handler runs whenever the shell exits: at the end, on exit, or when set -e stops it.

In more detail

It is the one place to put cleanup such as deleting a temporary directory. Set it straight after creating what it cleans up. The handler should leave the script's exit status alone so callers still see the real result.

Related terms

Taught in

References