Echo print space, echo print space
Edit a script to verify the md5 of files in batches
<Span style = "font-size: 18px;"> #! /Bin/bashmd5sum = "/usr/bin/md5sum" count = 0 # record how many files are involved in md5 comparison check = 0 # record how many files md5 is correct while read linedo echo-e $ line | $ md5sum-c if [$? -Eq 0]; then let check + = 1 fi let count + = 1 done <md5sum. md5echo "there are $ count files in total, among which $ check" </span>
When I run the command, I always prompt that my file is incorrectly formatted. My file is generated by md5sum. How can this problem be solved?
Then I run
echo "dbdf9049296c84c1f295e8c467a210d0 /usr/bin/grub-mkrescue" | md5sum -c
Is displayed correctly,
Then I ran it by chance.
echo "dbdf9049296c84c1f295e8c467a210d0 /usr/bin/grub-mkrescue" | md5sum -c
It turns out to be wrong. How is it possible?
I began to carefully compare and dizzy, with a space difference. Then, as a flash of thought, echo $ line treats consecutive spaces as one,
#! /Bin/bashmd5sum = "/usr/bin/md5sum" count = 0 # record how many files are involved in md5 comparison check = 0 # record how many files md5 is correct while read linedo echo-e "$ line" | $ md5sum-c if [$? -Eq 0]; then let check + = 1 fi let count + = 1 done <md5sum. md5echo "there are $ count files in total, of which the valid File $ check"
Pay attention to this issue when you learn it. Now let's take a look:
tmp="a b d"echo $tmpa b decho "$tmp"a b d
As for the reason, you need to understand the shell parsing process:
The execution process of echo $ tmp is:
Therefore, the output is a B d, and only one space is displayed.
Explanation reference: http://witmax.cn/shell-echo-spaces.html