Skip to content

Latest commit

 

History

History
21 lines (13 loc) · 366 Bytes

File metadata and controls

21 lines (13 loc) · 366 Bytes

Temporary file using mktemp and trap

To create a temporary file:

file=$(mktemp)

Why use mktemp instead of tempfile?

  • Because mktemp is available on more systems.

To remove a temporary file when the program exist:

trap "rm -f $file" EXIT

Why trap on EXIT, instead of TERM, INT, HUP?

  • Because EXIT covers all the cases.