Shell string Equality Comparison, note the processing when the string is empty

Source: Internet
Author: User



if ["$test" x = "Test" x]

Here are a few key points:
1 with a single equals sign, two equals signs can be
2 Note that there is a space on each side of the equal sign: This is the UNIX shell requirement
3 Notice the last X of "$test" X, which is deliberately arranged, because when $test is empty, the expression above becomes x = Testx, which is obviously not equal.


Without this x, the expression would be an error: [: =: unary operator expected

This article is from the Linux and networking blogs, so be sure to keep this source http://khaozi.blog.51cto.com/952782/1768437

Shell string Equality Comparison, note the processing when the string is empty

Related Article

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.