我明显错过了一些简单的东西,并且知道问题在于它创建了一个空白输出,这就是为什么它无法比较。但是,如果有人能够对此有所了解,那就太好了 - 我没有把它隔离开来。Bash循环来比较文件
最终,我试图将md5sum
从存储在txt文件中的列表与存储在服务器上的列表进行比较。如果有错误,我需要它来报告。以下是输出:
[email protected] [~/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
[email protected] [~/testinggrounds]# md5sum file*
2a53da1a6fbfc0bafdd96b0a2ea29515 file1
bcb35cddc47f3df844ff26e9e2167c96 file2
[email protected] [~/testinggrounds]# cat md5.txt
2a53da1a6fbfc0bafdd96b0a2ea29515 file1
bcb35cddc47f3df844ff26e9e2167c96 file2
内部'read'命令不是从封闭while循环继承stdin;它通过管道连接到'md5sum'。您正在通过在内部读取中使用流程替换(而不是管道)来解决问题,而不是通过为外部循环使用单独的文件描述符。 – chepner
@chepner - 你是对的,我更新了答案。 – jordanm