Application of test statements in the shell

Source: Internet
Author: User

The introduction of test statements in Linux can help us improve the efficiency of our tools and reduce the intensity of our work. So this article mainly introduces the introduction and usage of the test statement in the shell script of Linux.

I. Scope of the test statement

Integer, String, file


Second, the variable test statement syntax format

Test condition

[Test conditions]

Third, the test relationship

3.1 Variables Test relationship

= =-EQ//equals =-ne//Not equal to >=-ge//greater than or equal to >-GT//Greater than <=-le//less than or equal to <     ; -LT//Less than

3.2 File Test relationships

    test  $tes 1       //tests whether a string content is empty (null output is 0 otherwise not 0)     test -z  $tes 1    // Tests whether a string is not empty (the output is 0 if not null otherwise 1)     -d            //test file is a catalog file     -f           //test file is a normal file     -x            //whether the test file is an executable file     -r          // Test whether the price is a readable file     -w          //test file is a writable file     -e          //test file exists      -s          //Test text See if the size is empty. 

3.3 Testing the logical relationship

&&//logic and, only when two conditions are met, the result is true | | Logical OR, when two conditions have a satisfaction, the result is true

Iv. Examples of applications

Test $tes 1 = = $tes 2//variable $tes1 is equal to $tes2 [$tes 1 = = $tes 2]//variable with spaces on both sides [-F/ETC/PASSWD] [-D/ETC] [-X Bat H.SH] [-X bath.sh] [-f/etc/passwd] && [-X bath.sh]

V. Methods of verification

echo $? echo $? The output is 0, which means the test is correct and is not 0 error


This article is from the "11705634" blog, please be sure to keep this source http://11715634.blog.51cto.com/11705634/1840662

Application of test statements 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.