aboutsummaryrefslogtreecommitdiff
path: root/man/man1/mktd.1df
blob: 8224d2d76adf724188e945532a3df61a152f5729 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
.TH MKTD 1df "August 2016" "Manual page for mktd"
.SH NAME
.B mktd
\- try hard to safely create a temporary directory in a POSIX-compliant way
.SH SYNOPSIS
.B mktd
.br
.B mktd
foo
.SH DESCRIPTION
.B mktd
creates a temporary directory with a strong attempt at a random name in $TMPDIR
(defaults to /tmp), with a restrictive umask for the user running the script,
into which it should be safe to place temporary files.
.P
The author makes no guarantees about security, but this should be a lot safer
than just using a /tmp/$$ file.
.P
You could use it in a script like this:
.P
    td=
    cleanup() {
        [ "$td" ] && rm -fr -- "$td"
        if [ "$1" != EXIT ] ; then
            trap - "$1"
            kill "-$1" "$$"
        fi
    }
    for sig in EXIT HUP INT TERM ; do
        trap "cleanup $sig" "$sig"
    done
    td=$(mktd myprogram) || exit
.SH SEE ALSO
rndi(1df)
.br
<http://mywiki.wooledge.org/BashFAQ/062>
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>