我显然只是遗漏了一些东西,并且知道问题在于它正在创建一个空白输出,这就是它无法比较的原因。但是,如果有人可以阐明这一点,那就太好了 - 我还没有将其孤立。
最后,我试图将存储在 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
最佳答案
不是直接回答你的问题,而是md5sum(1) :
-c, --check
read MD5 sums from the FILEs and check them
喜欢:
$ ls
1.txt 2.txt md5.txt
$ cat md5.txt
d3b07384d113edec49eaa6238ad5ff00 1.txt
c157a79031e1c40f85931829bc5fc552 2.txt
$ md5sum -c md5.txt
1.txt: OK
2.txt: OK
关于linux - Bash循环比较文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12413097/