Print space of echo
Edit a script to verify the md5 of files in batches
#! /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
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
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:
Replace the variable to execute the command according to the parameters after the command is divided by IFS (a variable in the Shell script, IFS (Internal Field Seprator), Internal domain separator, the Section enclosed by "" and "is used as a parameter of the command.
The execution process of echo $ tmp is:
Replace variable: echo a B d run the command: echo a B d divide the parameters a, B, d after the echo command by IFS, that is, echo has three parameters, not one
Therefore, the output is a B d, and only one space is displayed.