Diff output from two programs without temporary files

Adding to both the answers, if you want to see a side by side comparison, use vimdiff:

vimdiff <(./a) <(./b)

Something like this:

enter image description here


For anyone curious, this is how you perform process substitution in using the Fish shell:

Bash:

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

Fish:

diff (./a | psub) (./b | psub)

Unfortunately the implementation in fish is currently deficient; fish will either hang or use a temporary file on disk. You also cannot use psub for output from your command.


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.

This is called "Process Substitution" in Bash's man page.


One option 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.

Tags:

File

Bash

Diff