Logo

TIL: cleanup temp files in shell commands w/ `trap`

Be a good boyscout and clean up after yourself!

After running a shell script you should clean temp files, this can be done through the trap command:

temp_file=$(mktemp)
trap "rm -f $temp_file" 0 2 3 15
....

rm ${temp_file}

See: https://www.linuxjournal.com/content/bash-trap-command