比较 Unix 中两个文件的差异以产生 bool

Comparing differences two files in Unix to produce bool

假设我有两个文件.. file1 & file2, 名称不同但内容相同

我尝试通过

比较它们
[[ file1 = file2 ]] 

& 使用

diff file1 file2
[[ echo $? ]]

然而两者 return 错误。

您正在寻找 cmp:

if cmp -s file1 file2; then
    echo "They're the same."
else
    echo "They're different"
fi