[英]Bash, how to print out that files are the same when using cmp
當文件相同時, cmp file1 file2
不執行任何操作。 那么如何在shell腳本中打印出相同的文件呢?
如果文件相同,則cpm
的退出狀態為零,否則為非零。 因此,您可以使用類似的東西
cmp file1 file2 && echo "Files are identical"
如果要保存退出狀態,可以使用以下內容:
cmp file1 file2
status=$?
if [[ $status = 0 ]]; then
echo "Files are the same"
else
echo "Files are different"
fi
使用cmp
的退出狀態代碼。 退出代碼為0表示它們是相同的:
$ cmp file1 file2; echo $?
0
在腳本中,您可以執行以下操作:
cmp file1 file2 && echo "same"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.