Shell condition Test Statement three methods

Source: Internet
Author: User
Tags bit set

1, test-f file 2, [-F file] 3, [[-F file]]

[-F file1-a-F file2] logic with [-f file1-o-F file2] logic or [-f file1] && [-f file2] the same as a string operation best double quotes such as-n-z = = = And a space is added to both sides of the equals sign .

# # #man Test

(EXPRESSION)
EXPRESSION is True

! EXPRESSION
EXPRESSION is False

Expression1-a EXPRESSION2
Both EXPRESSION1 and EXPRESSION2 are true

Expression1-o EXPRESSION2
Either EXPRESSION1 or EXPRESSION2 is true

-N STRING
The length of STRING is nonzero

String equivalent To-n string

-Z STRING
The length of STRING is zero

STRING1 = STRING2
The strings is equal

STRING1! = STRING2
The strings is not equal

Integer1-eq INTEGER2
INTEGER1 is equal to INTEGER2

Integer1-ge INTEGER2
INTEGER1 is greater than or equal to INTEGER2

INTEGER1-GT INTEGER2
INTEGER1 is greater than INTEGER2

Integer1-le INTEGER2
INTEGER1 is less than or equal to INTEGER2

Integer1-lt INTEGER2
INTEGER1 is less than INTEGER2

Integer1-ne INTEGER2
INTEGER1 isn't equal to INTEGER2

File1-ef FILE2
FILE1 and FILE2 have the same device and inode numbers

File1-nt FILE2
FILE1 is newer (modification date) than FILE2

File1-ot FILE2
FILE1 is older than FILE2

-B FILE
FILE exists and is block special

-C FILE
FILE exists and is character special

-D FILE
FILE exists and is a directory

-E FILE
FILE exists

-F FILE
File exists and is a regular file

-G FILE
FILE exists and is Set-group-id

-G FILE
FILE exists and is owned by the effective group ID

-H FILE
FILE exists and is a symbolic link (same as-l)

-K FILE
FILE exists and have its sticky bit set

-L FILE
FILE exists and is a symbolic link (same as-h)

-O FILE
FILE exists and is owned by the effective user ID

-P FILE
FILE exists and is a named pipe

-R FILE
FILE exists and Read permission is granted

-S FILE
FILE exists and has a size greater than zero

-S FILE
FILE exists and is a socket

-T FD file descriptor FD is opened on a terminal

-U FILE
FILE exists and its set-user-id bit is set

-W FILE
FILE exists and write permission is granted

-X FILE
FILE exists and execute (or search) permission is granted

Except for-h and-l, all file-related tests dereference symbolic links. Beware that parentheses need to be
Escaped (e.g., by backslashes) for shells. INTEGER may also be-l STRING, which evaluates to the length of
STRING.

Shell condition Test Statement three methods

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.