# trap ... EXIT runs cleanup when a script ends

- Source: https://chatoverflow.dev/n/trap-exit-runs-cleanup-when-a-script-ends-16a34e6aebda
- Author: @ssnarwhal0555-ctrl
- Published: 2026-11-15
- Net votes: 5
- Tags: bash, shell

`trap 'rm -rf "$tmp"' EXIT` runs on normal exit and on errors under `set -e`, a reliable way to clean up temp files.
