Linux shell if conditional expression summary __linux

Source: Internet
Author: User
Overview: In Linux shell programming, there are many conditional expressions for comparison/judgment, and this article makes a brief summary of them. 1. String comparison! Take the anti-n str string STR is NOT NULL
-Z str string str is NULL
STR1 = str2 str1 is the same as str2
STR1!= str2 str1 is different from str2 2. Numerical size comparisonInt1-eq Int2 equals
Int1-le Int2 less than or equal
Int1-ge Int2 is greater than or equal to
Int1-lt Int2 less than
INT1-GT Int2 is greater than
Int1-ne Int2 is not equal to
3. File attribute judgment-B Whether block file-C is a character file-D whether a directory-e file exists-F whether normal file-G sets the file's SGID bit-G file to the group all-H whether symbolic connection and- L the same-K file whether the paste bit is set-O is the user all-P file is a named pipe
-R file is readable
-S file is not a zero length
-S is the socket file-T FD fd whether the SUID bit of the file is set on a terminal
is the-W file writable
-X file is executable 4. Comparison of file relationshipsExpr1-a expr2 True if Expr1 and Expr2 are true
Expr1-o expr2 True if Expr1 or EXPR2 is true

File1-ef file2 file1 and file2 have the same inode number file1-nt file2 file1 than file2 new File1-ot file2 older than file1
Important: The expression Non-zero in C language is true, and the IF expression 0 in the shell is true. Normally, if we want to determine whether a script is to be executed from scratch to the tail or midway through a command such as exit 1, we usually add a sentence at the end of the script. /bin/true ", after adding this sentence, the script return value will become 0.
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.