Shell Judgment Statement

Source: Internet
Author: User

File judgment operator
–b return True when file exists and is a block file
-C Returns True when file exists and is a character
-D returns True when pathname exists and is a directory
-E Returns True when a file or directory specified by pathname is present
-F Returns True when file exists and is regular
-G returns True when the file or directory specified by pathname is present and the Sgid bit is set
-H Returns True when file exists and is a symbolic link file, this option is not valid on some old systems
-K returns True when a file or directory specified by pathname exists and the "sticky" bit is set
-L filename True if filename is a symbolic link [-l/usr/bin/grep]
-P Returns True when file exists and is a command pipeline
-R Returns True when the file or directory specified by pathname is present and readable
-W filename if filename is writable, true
-s when file size is larger than 0 o'clock returns true
-U returns True when the file or directory specified by pathname is present and the SUID bit is set
-O Returns True when the file or directory specified by pathname is present and is owned by the user specified by the active user ID of the current process.

File comparison Operators
Filename1-nt filename2 If filename1 is newer than filename2, then true [/tmp/install/etc/services-nt/etc/services]
Filename1-ot filename2 If filename1 is older than filename2, then true [/boot/bzimage-ot Arch/i386/boot/bzimage]

string comparison operators (note the use of quotation marks, which is a good way to prevent whitespace from disturbing the code)
-Z String True if string length is zero [-Z $myvar]
-N String if string length is nonzero, true [-N $myvar]
string1 = string2 true if string1 is the same as string2 [$myvar = one of the three]
String1! = string2 true if string1 is different from string2 [$myvar! = one, three]

Arithmetic comparison operators
Num1-eq num2 equals [3-eq $mynum]
Num1-ne num2 Not equal to [3-ne $mynum]
Num1-lt num2 less than [3-lt $mynum]
Num1-le num2 less than or equal to [3-le $mynum]
NUM1-GT num2 greater than [3-GT $mynum]
Num1-ge num2 greater than or equal to [3-ge $mynum]

and -A

or -O

Shell Judgment Statement

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.