Bash,使用cmp时如何打印出来的文件是一样的

kul*_*lan 3 bash cmp

cmp file1 file2文件相同时什么都不做.那么如何在shell脚本中打印出相同的文件呢?

che*_*ner 5

cpm如果文件相同则退出状态为零,否则为非零.因此,您可以使用类似的东西

cmp file1 file2 && echo "Files are identical"
Run Code Online (Sandbox Code Playgroud)

如果要保存退出状态,可以使用以下内容:

cmp file1 file2
status=$?
if [[ $status = 0 ]]; then
    echo "Files are the same"
else
    echo "Files are different"
fi
Run Code Online (Sandbox Code Playgroud)