Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Some commands only output to stdout.
Some tools only work on files.
Is there a command that can glue those together?

Contrived simple example:

diff $(echo 1 | stdout-to-temp-file) $(echo 2 | stdout-to-temp-file)

My actual use case; Current workaround:

git show HEAD:$1 > /tmp/left && meld /tmp/left $1

My actual use case; Desired:

meld $(git show HEAD:$1 | stdout-to-temp-file) $1

I'd use this in a few other situations too (i.e. I'm not looking for a git or meld only fix).

share|improve this question
up vote 7 down vote accepted

You could use < to redirect your output to stdin.

I don't know how meld works, but about your diff example, here's how it would work:

Using tempfiles

$ cmd1 > file1.tmp
$ cmd2 > file2.tmp
$ diff file1.tmp file2.tmp

Without tempfiles

$ diff <(cmd1) <(cmd2)

Note that syntax may vary a bit according to the shell you're using (I'm using ksh88).

share|improve this answer
+1, but that's not redirection. It is Process Substitution ... Process substitution uses /dev/fd/<n> ... eg gedit <(echo Hello) will open a file named 63 or some such fd number, and the "Hello", which was sent to stdout, simply vanishes into the bit-bucket of that process, because gedit doesn't accept stdin, eg echo Hello | gedit. – Peter.O Oct 7 '11 at 13:32
Process substitution isn't POSIX standard, and isn't available on every shell out there, so be aware of that if you're using it in a script. – Shawn J. Goff Oct 7 '11 at 20:25

mktemp will create a temporary filename for you. Save the filename in a variable, and use that in both slots.

For a better solution for your precise problem, check out git difftool. I have mine setup to use meld, and it's pretty great.

share|improve this answer
This is the right way to go - much better than using a fixed file name. – ConcernedOfTunbridgeWells Oct 7 '11 at 13:25
+1 for both mktemp and difftool. An alternative to mktemp is tempfile or a file name composed using $$ variable (less secure). – rozcietrzewiacz Oct 7 '11 at 13:43

I've never used meld but you can accomplish this typically using the - argument to most cli utilities. e.g.

cat /path/to/left/file | diff /input/from/right/file -

Specifically for your meld command you might try something like:

git show HEAD:$1 | meld - $1
share|improve this answer
oops initial diff command was incorrect – frogstarr78 Oct 7 '11 at 19:18

Your Answer


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.