Vi. condition testing and selection 6.1 test expression
-file Status Test
6.1.1 [-E file]
File exists with a value of true;file does not exist as false
6.1.2 [-D file]
File exists and is a directory with a value of true;file does not exist as false
6.1.3 [-F file]
File exists and the value for True;file does not exist as false
6.1.4 [-R File]
File has r permission with a value of True;file without r permission and a value of false
6.1.5 [w file]
File has W permission with a value of True;file without W permission and a value of false
6.1.6 [x file]
File has x permission with a value of true;file without x permission and a value of false
-Integer size Test
6.1.7 [X-gt y]
X>y
6.1.8 [X-ge y]
X≧y
Greater than or equal
6.1.9 [X-eq y]
X=y
Equals
6.1.10 [X-ne y]
X!=y
Not equal to
6.1.11 [X-lt y]
x< y
Less than
6.1.12 [X-le y]
X≦y
Less than or equal
-String test
6.1.13 [' x ' = = ' Y ']
' X ' is the same as ' Y '
String test
6.1.14 [' x '! = ' Y ']
' x ' differs from ' y '
String test
6.1.15 [-N "string"]
Determines whether a string has a value, has a value of true, and has no value of false
6.1.16 [-Z "string"]
Determines whether a string is empty, is null, is true, is not NULL, or FALSE
-Multiple criteria determination
6.1.17-a
And and
6.1.18-o
OR OR
6.2 If condition test 6.2.1 if single loop
if condition test; then
Command XX
Fi
6.2.2 If double loop
if condition test; then
Command XX
Else
Command yy
Fi
6.2.3 If multi-loop
if condition test; then
Command XX
elif condition Test 1;then
Command yy
Else
Command ZZ
Fi
6.2.4 the difference between empty value and no
A null value indicates that the value is empty
There is no indication that there is no
"$" = = Redhat #给变量加上双引号可以将 "No" into "null"
Examples of scripts:
#!/bin/bash if [ "$1" == redhat ];then echo fedora elif [ "$1" == fedora ];then echo redhat else echo ‘/root/foo.sh redhat|fedora‘ >&2 # >&2表示这个echo为错误输出fi
6.3 For loop structure
Perform the same operation repeatedly, depending on the value of the variable, until the variable has no value and exits the loop
For variable name in value list
Do
Command XX
Done
DAY11 Shell Script Basics (enginner05-2)