Bash循环来比较文件

cbc*_*bcp 4 linux bash loops if-statement while-loop

我显然遗漏了一些东西,并且知道问题是它创建了一个空白输出,这就是为什么它无法比较.然而,如果有人能够对此有所了解,那就太棒了 - 我没有把它隔离开来.

最后,我试图将md5sum存储在txt文件中的列表与存储在服务器上的列表进行比较.如果有错误,我需要它报告.这是输出:

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
Run Code Online (Sandbox Code Playgroud)

the*_*mel 7

不是直接回答你的问题,而是md5sum(1):

-c, --check
read MD5 sums from the FILEs and check them
Run Code Online (Sandbox Code Playgroud)

喜欢:

$ 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
Run Code Online (Sandbox Code Playgroud)