0
A
回答
2
如果您想檢查兩個文件是否相同,您可以檢查diff -q
(或cmp
)的退出代碼。這是更快,因爲它不需要找到確切的差異:
if diff -q file1 file2 > /dev/null
then
echo "The files are equal"
else
echo "The files are different or inaccessible"
fi
所有的Unix工具有一個退出代碼,通常速度更快的,更簡單,更強大的檢查,而不是捕捉和比較在它們的輸出基於文本的方式。
0
可以使用邏輯管:
對於一個命令:
diff -q file1 file2 > /dev/null && echo "The files are equal"
或多個命令:
diff -q file1 file2 > /dev/null && {
echo "The files are equal"; echo "Other command"
echo "More other command"
}
相關問題
- 1. 其條件爲真在if語句
- 2. if語句中if語句的條件
- 3. while/if語句中的多個條件在任何條件爲真時運行?
- 4. Eclipse Java調試器使if語句條件成立爲真
- 5. MariaDB版本:if語句差異
- 6. IF語句條件
- 7. console.log作爲if語句中的條件
- 8. 如何將if語句或條件轉換爲三元語句?
- 9. 即使「if」語句在PHP中爲真,其他語句也會運行
- 10. if if語句中的兩個條件
- 11. 條件if/else語句
- 12. 如何在If語句中使用NSMutableString作爲條件
- 13. 如何在MATLAB中寫這個if語句的條件語句?
- 14. 3條件中的一條if語句
- 15. ASH if if語句中的if語句
- 16. If語句中的多個條件
- 17. 確定條件語句中的單個語句爲真
- 18. if語句中的多個或條件
- 19. 團結在一個條件語句IF不同的條件語句IF(JavaScript)的
- 20. Python「if」語句 - 如果xpath爲真
- 21. JQuery if語句條件
- 22. SQL中的IF語句中的條件
- 23. Python條件語句和if語句
- 24. 想寫IF條件語句
- 25. if語句中的常量條件
- 26. 如何使用SQLite中的條件(如if語句等)
- 27. 如果條件爲真,則使用if else語句清除JavaScript超時
- 28. 多條件if語句C++
- 29. 如何在html中的if語句中使用2個條件
- 30. 如何在Ada中的if語句中使用多個條件