Linux Shell Learning notes-compare operations

Source: Internet
Author: User

integer comparison-eq equals, as:if["$a"-eq"$b" ]-ne not equal to, such as:if["$a"-ne"$b" ]-GT greater than, as:if["$a"-gt"$b" ]-ge is greater than or equal to, such as:if["$a"-ge"$b" ]-lt less than, such as:if["$a"-lt"$b" ]-le less than equals, such as:if["$a"-le"$b" ]< less (requires double brackets), such as: (("$a"<"$b"))<= is less than or equal (requires double brackets), such as: (("$a"<="$b"))> is greater than (requires double brackets), such as: (("$a">"$b"))>= is greater than or equal to (requires double brackets), such as: (("$a">="$b") ) string comparison= Equals, as:if["$a"="$b" ]= = equals, as:if["$a"=="$b"], and =Equivalence Note:==the functions in [[]] and [] are different, as follows:1[[$a = = z*]] # if $ A"Z"Start (Pattern match) then true2[[$a = ="z*"] # if $ A equals z*(character match), then the result is true34[$a = = z*] # File globbing and Word splitting will occur5["$a"=="z*"] # if $ A equals z*(character match), then the result is true to explain that file globbing is a shorthand for files, such as"*.c"is, again like ~but, too.fileglobbing is not a strict regular expression, although in most cases the structure is more like.! = does not equal, such as:if["$a"!="$b" ]<less than, in ASCII alphabetical order. such as:if[["$a"<"$b" ]]if["$a"\<"$b"] Note: In the [] structure"<"need to be escaped.>greater than, in ASCII alphabetical order. such as:if[["$a">"$b" ]]if["$a"\>"$b"] Note: In the [] structure">"need to be escaped. Specific reference Example -- Oneto see an example of this operator application.-Z string is"NULL". That is, the length is 0.-N String not for"NULL"Note: Use-N test in [] structure must be used""The variable. Use a non-""The string to use! -Z or just not used""The referenced string itself, placed in the [] structure (see example7-6Although it is generally possible to work, it is unsafe. Accustomed to use""It's a good habit to test strings. [1]

Linux Shell Learning notes-compare operations

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.