Shell Test condition judgment

Source: Internet
Author: User

Test condition judgment

# symbol [] equals test command

Ten 5        # Judging the size of echo $?              # View the previous sentence The test command  returns the status "hello"     # To determine if the string length is 0[$  0"success" | | Exit # To determine the success hint, fail to exit

Expression is a string operation

-N STR   # string str is not empty-Z str   # string str is empty

 Expression for file operation

-A     # and, two conditions are true-B     # whether the block file     -P # file is a named pipe-C     # Whether the character file-   r     # file is readable-D     # whether a directory   -S     # Whether the length of the file is not zero-e     # The file exists if-   s # is     a socket file-F # whether the     normal file-   x # file is executable or     true-G     # Whether to set the file's SGID bit-u     # If the file's SUID bit-G     # File exists and is owned by the group All-W     # file is writable, then true-K     # file is set paste bit-  t fd
   
    # FD is an open file descriptor that is connected to the terminal (FD defaults to 1)-O     # or, a condition is true-o     # file exists and is owned by the user!      # Take the reverse
   

 Expression is an integer operation

Expr1-a EXPR2   # If the EXPR1 and EXPR2 evaluates to True, then true Expr1-o expr2   # True if EXPR1 or EXPR2 evaluates to True

 Two-value comparison

integer     string -lt      <         # less than -gt      >         # greater than -le      <=        # Less than or equal to-ge      >=        # is greater than or equal to-eq      = =        # equals -ne!      =        # does not equal

Shell Test 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.