Echo print space, echo print space

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.