1

2 つのファイルの md5sum を作成し、2 つのファイルが一致することを確認する UNIX スクリプトがあります。これはスクリプトの例ですが、これはファイルを正しく比較していません - 誰でもこれに光を当てることができますか?

md5sum version1.txt >> file1
md5sum version2.txt >> file2

if [ $file1 == $file2 ]
then
    echo "Files have the same content"
else
    echo "Files have NOT the same content"
fi
4

3 に答える 3

4
HASH1=`md5sum version1.txt | cut -f1 -d ' '`
HASH2=`md5sum version2.txt | cut -f1 -d ' '`

if [ "$HASH1" = "$HASH2" ]; then
    echo "Files have the same content"
else
    echo "Files have NOT the same content"
fi

または:

if cmp -s version1.txt version2.txt; then
    echo "Files have the same content"
else
    echo "Files have NOT the same content"
fi
于 2013-09-20T06:46:37.153 に答える
-2
if [ "$file1" == "$file2" ]
then
    echo "Files have the same content"
else
    echo "Files have NOT the same content"
fi
于 2013-09-20T06:50:13.777 に答える