Closed gdevenyi closed 4 years ago
i've been using following piece of code in many scripts:
tempdir=$(mktemp -d --tmpdir)
trap "rm -rf $tempdir" 0 1 2 15
Thanks @vfonov after reading the POSIX spec it seems that EXIT is not sufficient to cover all the codes, I'll fix that up with the named equivalents.
Added a more compact version that lists more exit signals. Thanks to @vfonov 's example.
I have omitted the "--tmpdir" argument, as manpage:
If TEMPLATE is not specified, use tmp.XXXXXXXXXX, and --tmpdir is implied.
@zijdenbos
Fixes #105
Here's a draft of fixes for the tmpdir handling, locally for me they now get created and cleaned up on exit.
A note regarding cluster integration, since we're now honouring the environment "TMPDIR" variable with mktemp, even if the job is interrupted, the TMPDIR is set by most cluster systems to be job-id linked, so when the job goes away, the cluster cleans up the directory. Nevertheless I also added an exit trap for cleanup.