/ Tech

Compare outputs of commands with Diff

Comparing two files with the diff utility is an easy task

diff <file1> <file2>

But if you want to compare the output of two commands without temporarily saving it to a file, it's a bit more complicated, because diff needs two inputs:

diff -u <(echo output1) <(echo output2)
--- /proc/self/fd/11    2013-07-29 10:59:06.037561642 +0200
+++ /proc/self/fd/12    2013-07-29 10:59:06.037561642 +0200
@@ -1 +1 @@
-output1
+output2

As we can see, the shell creates two file-descriptors from the stdin input.