trap 'cleanup' EXIT

Category: Shell & Bash

trap 'cleanup' EXIT

Run a function or command when the script exits

Sets up a cleanup action: when the script exits (for any reason), the specified function or command will run automatically.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.