The main differences between [[]] and [] in the shell

Source: Internet
Author: User
[] is actually shorthand for the test command in bash. That is, all [expr] equals test expr

For the test command, use-eq to make a numeric comparison, and when you pass in the string, you get an error.

[[expr]] is a real conditional judgment statement in Bash whose syntax is more in line with programming habits (such as &&, | | ), although I think the intentional string to-eq in [[]] should also be as error as test, but it is obvious that the bash implementation directly converts a non-integer string directly to 0 (you can verify it yourself, in [[]], any need for an integer, but the supply is indeed another that cannot be converted to an integer String, all of them become 0). This should be the result of a bash implementation that does not check for content on either side of the-EQ operator in [[]]. For us, there is no need to drill these things, and we should make sure that we always provide integers when we need to use integers in our code.

The main differences between [[]] and [] in the shell

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.