Questions tagged [mktemp]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
8
votes
1answer
242 views

mktemp on macOS not honouring $TMPDIR

I've noticed this before, but it was brought up again as I was answering "How to move directory into a directory with the same name?": The mktemp utility on macOS does not behave the same as the ...
-1
votes
1answer
99 views

Why is mktemp -u considered “unsafe”?

I read the --help text for mktemp recently (the man page wasn't available) and came upon this: -u, --dry-run do not create anything; merely print a name (unsafe) Why is this "unsafe"? Is ...
0
votes
1answer
78 views

Deleting temporary direction via trap

I have a script which looks like this: #!/bin/bash set -e tmpdir=$(mktemp -d) pushd $tmpdir trap 'popd && rm -rf $tmpdir' EXIT # Business logic which may succeed or fail... /bin/false ...
1
vote
2answers
576 views

Is there a programmatical difference between directories created with mktemp -d or mkdir?

I try to understand Stephen Kitt's answer to this question where he created a temporary directory with the following code: #!/bin/bash scripttmp=$(mktemp -d) # Create a temporary directory (these ...
1
vote
1answer
81 views

Is it OK to overwrite a file created by mktemp?

I'd like to copy a file to a temporary location. I'd like to make sure I'm not overwriting anything important, and that I know the location of the file while the script is running. #!/bin/bash ...
0
votes
2answers
46 views

Can a script unmount the volume containing itself?

I have a computer with a hard drive mounted read-only. I am running a script from a flash drive. I would like the script to be able to unmount the flash drive, but this can't be performed as the ...
1
vote
1answer
208 views

`mktemp -d` followed by `pushd` works fine on command line, but not when in a script

If I paste these lines into a command prompt on Debian... DIR=$(mktemp -d -t bbbrtc.XXXXXX) || exit 1 echo "tmpdir = $DIR" cd "$DIR" They make a new temp directory, print the directory name, and ...
1
vote
2answers
815 views

Improving mktemp

I am wondering how to best improve on mktemp for use with encrypted containers or file systems. The issue that I am dealing with is that I would like my shell scripts to store temporary files inside ...
3
votes
3answers
16k views

How to create multiple files/directories with randomized names?

I'm trying to create some files that has different names and with different extensions. Let say I want to create for example 3 files with following name and extension: File001.000 File002.001 File003....