4

How does one go about using diff to compare the output of two commands?

I know how to use it to compare the contents of a file filename1 with the output of a command cmd2:

cmd | diff filename -

How do I make it so that I can have another command, say cmd1 in place of filename?

I'm using dash, which doesn't support process substitution.

Stephen Kitt
  • 434,908

2 Answers2

7

Based on How to emulate Process Substitution in Dash? (thanks αғsнιη!), adjusted for dash:

( cmd1 | ( cmd2 | ( diff /dev/fd/3 /dev/fd/4 ) 4<&0 ) 3<&0 )
Stephen Kitt
  • 434,908
0

easy :-)

$ cat file1 | diff /dev/stdin /dev/stderr 2<< EOT
> `cat file2`
> EOT
2c2
< 2
---
> 4
defdefred
  • 61
  • 1
  • 2