Common conditions in the Shell to judge

Source: Internet
Author: User
Tags valid

-B file if it exists and is a block special file, True
-C file If it exists and is a character special file, True
-D file if it exists and is a directory, true
-e File is true if it exists
-F file is true if it exists and is a rule file
-G file is true if it exists and the value of the Sgid bit is set
-H file is true if it exists and is a compliant link
-K file if it exists and the value of "sticky" bit is set
-P file If it exists and is a named pipe, true
-R file if it exists and is readable, true
-S file is true if it exists and its size is greater than 0
-U file is true if it exists and the SUID bit is set
-W file is true if it exists and is writable
-X file is true if the file exists and is executable
-O file is true if it exists and is owned by a valid user ID

-Z String True if string length is 0
-N String True if string length is not 0
string1 = string2 true if two strings are equal
String1! = string2 true if two strings are not equal

Int1-eq int2 if Int1 equals Int2, then true
Int1-ne Int2 If int1 is not equal to Int2, then true
Int1-lt Int2 If Int1 is less than Int2, it is true
Int1-le Int2 If int1 is less than or equal to Int2, then true
INT1-GT Int2 If Int1 is greater than Int2, then true
Int1-ge Int2 If int1 is greater than or equal to Int2, then true

!expr If expr is false, the compound expression is true. Expr can be any valid test expression
Expr1-a expr2 if Expr1 and Expr2 are true, the whole is true.
Expr1-o expr2 if Expr1 and Expr2 have a true-to-real

Special variable The name of the command that is being executed. For shell scripts, this is the path to the activated command
$n the variable corresponds to the parameter that was taken when the script was activated. n is a positive integer that corresponds to the position of the parameter ($1,$2 ...)
$# provides the parameter number of the script
$* all these parameters are enclosed in double quotation marks. If a script receives two parameters, $* equals $1$2
$@ all these parameters are enclosed in double quotation marks, respectively. If a script receives two parameters, $@ is equivalent to $1$2
$? Exit status after the previous command was executed
$$ the process number of the current shell. For shell scripts, this is the process ID when it is executing
$! The process number of the previous background command

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.