Shell condition judgment

Source: Internet
Author: User
Tags locale posix readable sorts

1. string Judgments

STR1 = str2

True when two strings have the same content, length

Str1! = str2

True when strings str1 and str2 are unequal

-N str1

True when the length of a string is greater than 0 (string non-null)

-Z str1

True when the length of the string is 0 (empty string)

Str1

True when the string str1 is non-empty

2. Judgment of numbers

Int1-eq Int2

Two numbers equal to True

Int1-ne Int2

Two numbers are true.

INT1-GT Int2

Int1 greater than Int2 is true

Int1-ge Int2

Int1 greater than or equal to Int2 true

Int1-lt Int2

Int1 less than Int2 is true

Int1-le Int2

Int1 less than or equal to Int2 true

3. Judgment of documents

-R File

User-readable as true

-W File

User can write as true

-X File

User can perform a true

-F File

File is true for regular files

-D File

File is directory-True

-C file

File is true for character special files

-B File

File is true for block special files

-S file

File non-0 o'clock is true

-T file

True if the specified device is terminal when the file descriptor (default is 1)

4. complex logic judgment

-A

And

-O

Or

!

Non -

[-A FILE] ifFILE exists is true.
[-B FILE] IfFile exists and is a block of special files is true.
[-C FILE] IfFile exists and is a word for special files is true.
[-D FILE] IfFILE exists and is a directory is true.
[-e FILE] IfFILE exists is true.
[-F FILE] IfFile exists and is a normal file is true.
[-G FILE] IfFILE exists and has been setThe Sgid is true.[-H FILE] IfFILE exists and is a symbolic join is true.
[-K FILE] IfTrue if FILE exists and the sticky bit has been set.
[-P FILE] IfFILE exists and is a name pipe(F ifO) is true.
[-R FILE] IfTrue if FILE exists and is readable.
[-S FILE] ifFILE exists and size is not0 is true.
[-T FD] if the file descriptorFD is turned on and pointing to a terminal is true.
[-U FILE] IfFILE exists and is setThe SUID (set user ID) is true.
[-W FILE] IfFILE ifTrue if FILE exists and is writable.
[-X FILE] IfTrue if FILE exists and is executable.
[-O FILE] IfFILE exists and is a valid userThe ID is true.
[-G FILE] IfFILE exists and is valid user group is true.
[-L FILE] IfFILE exists and is a symbolic join is true.
[-N FILE] IfFILE existsand has been mod ifIED since it is last read is true.
[-S FILE] ifFILE exists and is a socket true.
[File1-nt FILE2] IfFILE1 have been changed more recently than FILE2, or ifFILE1 exists and FILE2 does not are true.
[File1-ot FILE2] IfFILE1 ratioFILE2 to be old.OrFILE2 exists andFILE1 is true if it does not exist.
[File1-ef FILE2] IfFILE1 andFILE2 points to the same device and the node number is true.
[-O optionname] IfShell options  "Optionname"   is true.   
[-Z string]  ' string '   is true for a length of zero.   
[-N string] or [string]  "string"   length is not 0   The Non-zero is true.   
[STRING1 = = STRING2]   if 2 strings are the same.   "=" May is used instead of "= =" for strict POSIX compliance is true.   
[STRING1! = STRING2]   If the strings are not equal.  
[STRING1 < STRING2]   if   "STRING1" sorts before " STRING2 "lexicographically in the current locale is true.   
[STRING1 > STRING2]   if   "STRING1" sorts After ' STRING2 ' lexicographically in the current locale is true.  

[-A FILE] ifFILE exists is true.
[-B FILE] IfFile exists and is a block of special files is true.
[-C FILE] IfFile exists and is a word for special files is true.
[-D FILE] IfFILE exists and is a directory is true.
[-e FILE] IfFILE exists is true.
[-F FILE] IfFile exists and is a normal file is true.
[-G FILE] IfFILE exists and has been setThe Sgid is true.[-H FILE] IfFILE exists and is a symbolic join is true.
[-K FILE] IfTrue if FILE exists and the sticky bit has been set.
[-P FILE] IfFILE exists and is a name pipe(F ifO) is true.
[-R FILE] IfTrue if FILE exists and is readable.
[-S FILE] ifFILE exists and size is not0 is true.
[-T FD] if the file descriptorFD is turned on and pointing to a terminal is true.
[-U FILE] IfFILE exists and is setThe SUID (set user ID) is true.
[-W FILE] IfFILE ifTrue if FILE exists and is writable.
[-X FILE] IfTrue if FILE exists and is executable.
[-O FILE] IfFILE exists and is a valid userThe ID is true.
[-G FILE] IfFILE exists and is valid user group is true.
[-L FILE] IfFILE exists and is a symbolic join is true.
[-N FILE] IfFILE existsand has been mod ifIED since it is last read is true.
[-S FILE] ifFILE exists and is a socket true.
[File1-nt FILE2] IfFILE1 have been changed more recently than FILE2, or ifFILE1 exists and FILE2 does not are true.
[File1-ot FILE2] IfFILE1 ratioFILE2 to be old.OrFILE2 exists andFILE1 is true if it does not exist.
[File1-ef FILE2] IfFILE1 andFILE2 points to the same device and the node number is true.
[-O optionname] IfShell options  "Optionname"   is true.   
[-Z string]  ' string '   is true for a length of zero.   
[-N string] or [string]  "string"   length is not 0   The Non-zero is true.   
[STRING1 = = STRING2]   if 2 strings are the same.   "=" May is used instead of "= =" for strict POSIX compliance is true.   
[STRING1! = STRING2]   If the strings are not equal.  
[STRING1 < STRING2]   if   "STRING1" sorts before " STRING2 "lexicographically in the current locale is true.   
[STRING1 > STRING2]   if   "STRING1" sorts After ' STRING2 ' lexicographically in the current locale is true.  

Shell condition judgment

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.