Conditional testing in the shell

Source: Internet
Author: User

Test command usage:


1) Judgment expression
if test (expression is true)
if test! An expression is false
test expression 1–a expression 22 expressions are true
test expression 1–o expression 22 expressions have a true


2) Judging the string
test–n String string length is not 0
Test–z String String has a length of zero
Test String 1 = string 2 string equal
Test string 1! = string 2 string unequal


3) Judging integers
Test integer 1–eq integer 2 integer equal
Test integer 1–ge integer 2 integer 1 greater than or equal to integer 2
Test integer 1–gt integer 2 integer 1 greater than integer 2
Test integer 1–le integer 2 integer 1 less than or equal to integer 2
Test integer 1–lt integer 2 integer 1 less than integer 2
Test integer 1–ne integer 2 integer 1 not equal to Integer 2


4) Judgment document
test File1–ef File2 two files with the same device number and I node number
Test file1–nt File2 file 1 compared to document 2,;;
test–b file files exist and are block device files
test–c file files exist and are character device files
test–d file files exist and are directories
test–e file files exist
test–f file files exist and are regular files
test–g file exists and the group ID is set
test–g file files exist and belong to valid group ID
test–h file exists and is a symbolic link (same-l)
test–k file files exist and sticky bits are set
test–b file files exist and are block device files
test–l file exists and is a symbolic link (same-h)
test–o file files exist and belong to valid user ID
test–p file exists and is a named pipe
test–r file files exist and are readable
Test–s file exists and is a socket
test–t FD file descriptor is opened in a terminal

Conditional testing in the shell

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.