我的文件中有一些類似的命令
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"