Linux file Test action

Source: Internet
Author: User

1. File test operation

true If ... -e file exists -a  file with this option has the same effect as-E. But it has been deprecated and is not encouraged to use -f file  is a regular ( is not a directory or device file)-s  0-d file is a directory -r  file has read permissions (for users to run this test)-w file has Write permissions ( For the user to run this test)  -x file has execute permission (for the user to run this test)

2. 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"))

3. 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 thetrue2[[$a = ="z*"] # if $ A equals z* (character match), then the result istrue34[$a = = z*] # File globbing and Word splitting will occur5["$a"=="z*"] # if $ A equals z* (character match), then the result istruea little explanation, about file globbing is a shorthand for documents, such as"*.c"is, again like ~But the file globbing is not a strict regular expression, although in most cases the structure is more like.! = does not equal, such as:if["$a"!="$b"] This operator will use pattern matching in the [[]] structure.<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". is the length of0.-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

Linux file Test action

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.