How many "X"'s should I use to create temporary files safely and portably with `mktemp`?
0
votes
1
answer
358
views
From time to time, I create temporary files from shell scripts by invoking the command
mktemp
with 6 or more X
's in the argument TEMPLATE
. However, I am unsure if that amount will work with other implementations of mktemp
because I have found commands with different amounts (e.g., [here](https://github.com/moby/moby/blob/1ffc120558bdfd528fc5740d6b6ea7c49f402639/Makefile#L252) , [here](https://github.com/Asana/kubernetes/blob/486ec2b7c9f95a43a856d1d71077382bf6b23afa/cluster/common.sh#L512) , and [here](https://github.com/torvalds/linux/blob/f5837722ffecbbedf1b1dbab072a063565f0dad1/tools/testing/selftests/net/big_tcp.sh#L7)) .
I have researched a little bit and found the following:
- The GNU implementation of mktemp
requires three or more X
's.
- The OpenBSD implementation of mktemp
appears to require six X
's. However, I have little to no clue what the [underlying code](https://github.com/openbsd/src/blob/master/usr.bin/mktemp/mktemp.c#L80) does.
- The manuals for the FreeBSD implementation of the [mktemp
](https://man.freebsd.org/cgi/man.cgi?query=mktemp&sektion=1&n=1) command and [function](https://man.freebsd.org/cgi/man.cgi?query=mktemp&sektion=3&apropos=0&manpath=FreeBSD+14.0-RELEASE+and+Ports) are rather vague with how many X
's the template should have.
Asked by qqqq
(56 rep)
Dec 28, 2023, 09:47 PM
Last activity: Dec 29, 2023, 10:39 PM
Last activity: Dec 29, 2023, 10:39 PM