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