Diff

使用 diff 比較兩個命令的輸出

  • November 21, 2019

如何使用diff來比較兩個命令的輸出?

我知道如何使用它來比較文件的內容和filename1命令的輸出cmd2

cmd | diff filename -

我該如何做到,以便我可以有另一個命令,比如cmd1代替filename

我正在使用破折號,它不支持程序替換。

基於How to emulate Process Substitution in Dash? (感謝αғsнιη!),調整為dash

( cmd1 | ( cmd2 | ( diff /dev/fd/3 /dev/fd/4 ) 4<&0 ) 3<&0 )

簡單的 :-)

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

引用自:https://unix.stackexchange.com/questions/512467