views:

87

answers:

2

Say I have too programs a and b that I can run with ./a and ./b.

Is it possible to diff their outputs without first writing to temporary files?

+12  A: 

Use <(command) to pass one command's output to another program as if it were a file name. Bash pipes the program's output to a pipe and passes a file name like /dev/fd/63 to the outer command.

diff <(./a) <(./b)

Similarly you can use >(command) if you want to pipe something into a command.

John Kugelman
One drawback to be aware of is that if ./a or ./b fails, the caller will not find that out.
Alexander Pogrebnyak
The OP did tag the question bash, but for the record, this doesn't work in any other shell. It's a bash extension to the Posix utility standard.
DigitalRoss
+2  A: 

One options would be to use named pipes (FIFOs):

mkfifo a_fifo b_fifo
./a > a_fifo &
./b > b_fifo &
diff a_fifo b_fifo

... but John Kugelman's solution is much cleaner.

martin clayton