To create a temporary file:
file=$(mktemp)Why use mktemp instead of tempfile?
- Because
mktempis available on more systems.
To remove a temporary file when the program exist:
trap "rm -f $file" EXITWhy trap on EXIT, instead of TERM, INT, HUP?
- Because EXIT covers all the cases.