Shell script-Judging Type

Source: Internet
Author: User

Test-judged

See below:

1 Echo " exist " Echo " Not exist "

Determine if/opt/a.txt exists, output exist, otherwise output not exist

Test also has many uses:

  1. A "file type" judgment about a file name, such as TEST-E filename indicates whether or not it exists
    1. -e Whether the file name exists
    2. -f The file name exists and is a file
    3. -D whether the file name exists and is a directory
  2. Permissions on the file, such as Test-f fileName, to determine whether the file is readable
    1. -R
    2. -W
    3. -X
  3. For a comparison between two files, such as Test file1-nt file2
    1. -nt (newer than) to determine whether File1 is newer than file2
    2. -ot (older than) to determine whether File1 is older than file2
  4. About the judgments between two integers, such as test n1-eq N2
    1. -eq judgment equals
    2. -ne judgment is not equal
    3. -GT N1 greater than N2
    4. -lt N1 less than N2
    5. -ge greater than or equal to
    6. -le less than or equal to
  5. About string Comparisons
    1. Test-z String If string is an empty string, returns True
    2. Test-n String If string is an empty string, returns false
    3. Test STR1=STR2
    4. Test STR1!=STR2
  6. Multiple Criteria Determination
    1. -A two conditions are also established, such as Test-e file1-a-e file2, to determine whether File1 and file2 are present
    2. -O Any condition that is set up, such as Test-e File1-o-e file2,file1 or file2 any one presence returns True
    3. ! Negative, like test! -e File1, indicating that FILE1 does not exist returns true

[  ... ] Judging type

Often used in the judgment of IF statements

Note: Each component in [] must be separated by a space character; the variables are best enclosed in double quotation marks; constants are enclosed in double quotes

Shell script-Judging Type

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.