最後のdiffコマンドの出力を確認する

最後のdiffコマンドの出力を確認する

ファイル内に次のようなコマンドがあります

diff file1 file2
diff file3 file4

そして何か出力された場合、どのコマンドでこれが起こったのかを出力したい。

diff file1 file2
if (there was output from the diff command)
     print "file1 and file2 had the difference"
endif
diff file3 file4
if (there was output from the diff command)
     print "file3 and file4 had the difference"
endif

答え1

1差異がある場合、diff コマンドは で終了します。簡単な方法では、これを成功/失敗のチェックとして使用します。

diff file1 file2 || print "file1 and file2 had the difference"
diff file3 file4 || print "file3 and file4 had the difference"

関連情報