我显然只是遗漏了一些东西,并且知道问题在于它正在创建一个空白输出,这就是它无法比较的原因。但是,如果有人可以对此有所了解,那就太好了-我没有将其隔离。
最终,我试图将存储在 txt 文件中的列表中的 md5sum
与存储在服务器上的列表进行比较。如果有错误,我需要它来报告。这是输出:
root@vps [~/testinggrounds]# cat md5.txt | while read a b; do
> md5sum "$b" | read c d
> if [ "$a" != "$c" ] ; then
> echo "md5 of file $b does not match"
> fi
> done
md5 of file file1 does not match
md5 of file file2 does not match
root@vps [~/testinggrounds]# md5sum file*
2a53da1a6fbfc0bafdd96b0a2ea29515 file1
bcb35cddc47f3df844ff26e9e2167c96 file2
root@vps [~/testinggrounds]# cat md5.txt
2a53da1a6fbfc0bafdd96b0a2ea29515 file1
bcb35cddc47f3df844ff26e9e2167c96 file2
最佳答案
我不打算争论。我只是尽量避免从内部循环中进行双重读取。
#! /bin/bash
cat md5.txt | while read sum file
do
prev_sum=$(md5sum $file | awk '{print $1}')
if [ "$sum" != "$prev_sum" ]
then
echo "md5 of file $file does not match"
else
echo "$file is fine"
fi
done