Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [RFC] adding zmktemp command



Clinton Bunch wrote on Wed, 27 Mar 2019 21:18 +00:00:
> I'm thinking of adding a zmktemp command either in a new module (e.g. 
> zsh/tempfile) or in the zsh/files module.
...
> Thoughts?

A few.

- I wonder if implementing mktemp in the shell is easier than expecting
  people to install a third-party mktemp(1) binary with whatever
  functionality they desire.  BSD systems often have both BSD make and
  GNU make, so it's conceivable that HP-UX systems could have both the
  native mktemp(1) and a third-party one.
  
  (To be clear, I do not object to your RFC; I just wonder if there's a
  better solution to the underlying problem.)

- There's already a gettempname() function in the shell's C implementation;
  it relies on mktemp(3) being available.  A module implementation might
  be able to reuse that.

- O_EXCL is exposed by zsh/system's 'sysopen' builtin, so a pure zsh
  implementation should be possible.

(I think you're aware of the following, but for the record:)

There is a *limited* workaround: '() { … } =(:)' creates a tempfile (in
${TMPPREFIX:h}, if that's set).  The catch is that the file is deleted
when the anonymous function returns, so it's effectively a lexically
scoped tempfile.  And, of course, it's not a substitute for «mktemp -d».
(So, no, that's not a replacement to a proper mktemp(1).)

Cheers,

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author