Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm looking at a bash script someone else wrote that uses mktemp:

TEMP=`mktemp --directory`

However, this line does not work on my machine (OS X 10.6).

How would I fix this line so that it is cross-un*x-like-platform compatible? EDIT: An alternative command would be sufficient as well.

share|improve this question

2 Answers

up vote 3 down vote accepted

You have to supply a template. mktemp -d /tmp/foo.XXXX should work. I've never seen --directory; the -- suggests that it is a GNU extension.

share|improve this answer

Change --directory to -d. The former is a GNU-ism, but GNU mktemp from coreutils also supports -d. The mktemp in OS X is the same as from BSD, so -d should be pretty portable among systems that actually ship a mktemp program.

share|improve this answer
I just tried mktemp -d, and it does not work either. – mindeavor. Jan 26 '12 at 19:56
1  
Kyle has the complete answer. The mktemp on OS X requires a template. The script you're using assumes GNU conventions, which uses a default template if none is supplied. – James Sneeringer Jan 26 '12 at 21:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.