Bash

如何區分兩個命令的輸出?

  • February 13, 2019

如何使用該diff命令比較 2 個命令的輸出?

這樣的事情存在嗎?

diff  ($cat /etc/passwd) ($cut -f2/etc/passwd)

使用程序替換

diff <(cat /etc/passwd) <(cut -f2 /etc/passwd)

<(...)稱為程序替換。它將命令的輸出轉換為diff可以讀取的類似文件的對象。

雖然程序替換不是 POSIX,但 bash、ksh 和 zsh 都支持它。

2個命令輸出之間的區別:-

$ diff <(command1) <(command2)

命令輸出和文件之間的區別:-

$ diff <(command) filename

2個文件之間的區別:-

$ diff file1 file2

例如$ diff <(mount) <(cat /proc/mounts)

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