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)