BIC-MNI / minc-tools

Basic minc-tools from former minc repository
Other
29 stars 25 forks source link

Uniformize tmpdir handling in shell scripts #106

Closed gdevenyi closed 4 years ago

gdevenyi commented 4 years ago

@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.

vfonov commented 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
gdevenyi commented 4 years ago

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.

gdevenyi commented 4 years ago

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.