Shell Basics Learning (v) Test command

Source: Internet
Author: User

1. Numerical test

Parameters Description
-eq Equals is True
-gt is greater than true
-lt is less than true
-nq Not equal to True
-ge Greater than or equal to true
-le is less than or equal to true

Example:

num1=num2=if  test $[num1] eq $[num2]then      Echo  ' two numbers equal 'else       echo' two numbers are unequal ' fi

Output: Two numbers equal

2. String Test

Parameters Description
= Equals is True
! = Not equal to True
-Z String length is zero for true
-N String length is not 0 bit true

Example:

string1='liupf'string2='liupf'if test string1=string2then    echo' two strings equal 'Else     echo' two strings unequal 'fi
Output: Two strings equal

3. File test

Parameters Description
-E File name File exists as true
-W file name File exists and can be written as true
-R file name File exists and can be read as true
-X file name File exists and can be executed as true
-S file name File exists and has at least one string
-D file name For a directory to be true
-F file name For an ordinary file to be true
-C file name True if the file exists and is a character-specific file
-B file Name True if the file exists and is a block special file

Example:

  

CD/binif test-e./bashthen    echo' file already exists! ' Else    Echo ' file does not exist! ' fi
Output: File already exists

Shell Basics Learning (v) Test 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.