Shell condition Test

Source: Internet
Author: User

The shell condition test can be done in two ways:

Test parameters Testing Content

[Parameter test content]

First, test file type:

TEST-E file name (test file exists)

[-e FileName] Test file exists, note the space on both sides of the bracket

Test-f file name to determine if it is normal

test-d file name to determine whether it is a directory

Test-b file name to determine if block device files

TEST-C file name to determine if the character device files

Second, test file permissions:

Test-r file name to determine whether or not to read permissions

TEST-W filename to determine whether the file and write permission

Test-x filename to determine if the file has Execute permission

Test-s file name to determine whether files are non-blank, content is true

Comparison of three, two files:

[File1-nt File2] file1 is newer than file2

[File1-ot File2] file1 is older than file2

[File1-et File2] Fie1 and file2 are linked files

Four, two arrays between the judgment:

[N1 EQ N2] N1 and N2 are equal

[N1 NE n2] N1 and N2 are not equal

[N1 GT N2] N1 is greater than N2

[N1 LT N2] N1 is less than N2

[N1 GE N2] N1 greater than or equal to N2

[N1 le N2] N1 is less than or equal to N2

Five, string judgment:

[-Z string] Determines whether the string is empty

[String 1 = = String 2] Determine if string 1 equals string 2

[String 1!] = string 2] Determine if string 1 is not equal to string 2

Shell condition Test

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.