5

I want to use zsh's process substitution to create a temporary file that can then be read by another program. However, the file it generates has no file extension, so the program reading it refuses to continue.

This can be demonstrated by:

$ echo =(ls)
/tmp/zshmgIWvT

What I want to happen is it to produce a filename like /tmp/zshmgIWvT.wav

Can zsh do this?

Migwell
  • 407
  • 1
    Create and remove the temporary file yourself instead of relying on that "process substitution". eg. tmp=\mktemp -t XXXXXX.wav`; command1 > "$tmp"; command2 "$tmp"; rm "$tmp".=(...)is not a *process* substitution like<(...)or>(...)for the simple fact you have to wait for the process to finish before reading or writing to that file. Comparecat <(echo yes; sleep 1000)tocat =(echo yes; sleep 1000)`. –  Nov 18 '18 at 07:16

1 Answers1

12

Somewhere in the depths of zshparam(1) one may find:

   TMPSUFFIX
          A  filename  suffix which the shell will use for temporary files
          created by process substitutions (e.g., `=(list)').   Note  that
          the  value  should  include  a leading dot `.' if intended to be
          interpreted as a file extension.  The default is not  to  append
          any  suffix,  thus  this  parameter should be assigned only when
          needed and then unset again.

So

% () { TMPSUFFIX=.wav; print =(ls); unset TMPSUFFIX }
/Users/jhqdoe/tmp/zshsQhnnV.wav
% print $TMPSUFFIX

% 

You may also want to set TMPPREFIX especially on shared systems to help avoid various /tmp security flaws.

thrig
  • 34,938