Dus*_*ook 1 unix scripting if-statement
我有一个unix脚本,它将为两个文件创建md5sum,然后检查这两个文件是否匹配.这是脚本的一个示例 - 但这不是正确比较文件 - 任何人都可以对此有所了解吗?
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
Run Code Online (Sandbox Code Playgroud)
if [ "$(md5sum < version1.txt)" = "$(md5sum < version2.txt)" ]; then
echo "Files have the same content"
else
echo "Files have NOT the same content"
fi
Run Code Online (Sandbox Code Playgroud)
如果已经计算了其中一个MD5校验和并将其存储在文本文件中,则可以使用
if [ "$(md5sum < version1.txt)" = "$(awk '{print $1}' md5hash.txt)" ]; then
...
Run Code Online (Sandbox Code Playgroud)