3

When I create a random file on macOS with mktemp I get:

mktemp /tmp/test.XXXXXXX.json
mktemp: mkstemp failed on /tmp/test.XXXXXXX.json: File exists

It does not replace XXXXXXX with random string. Works fine on Linux but not on macOS.

chingis
  • 1,514
  • 2
  • 19
  • 38

2 Answers2

3

Turns out, for whatever reason, macOS version of mktemp supports only trailing XXXXXX for random string, in other words mktemp /tmp/test.XXXX will work but not /tmp/test.XXXX.json

chingis
  • 1,514
  • 2
  • 19
  • 38
1

This is the documented behaviour, from man mktemp:

The template may be any file name with some number of `Xs' appended to it, for example /tmp/temp.XXXXXX

TheNextman
  • 12,428
  • 2
  • 36
  • 75
  • yep, however, the behavior is different on Linux which isn't obvious – chingis May 28 '19 at 03:52
  • Well, the respective behaviours are pretty well documented on both sides. The macOS tools != GNU tools; if you find they don't behave the same, check the documentation, as it's likely they're *not* the same. – TheNextman May 28 '19 at 15:36