1. The test command has the following two forms:

1.1. The test [operator option] expression

1.2, [operator option expression] [] must have Spaces inside

Tips: The shell environment depends on the return value of the command ($?). When 0 is returned, the command is successfully executed (or the expression is true). Failure if the return value is non-zero (expression false)

1.3. File test operator

-e Tests whether the specified file or directory exists

-f Tests whether the specified object is a file. Whether the specified file exists

-d Tests whether the specified object is a directory. Whether the specified directory exists

-r Tests whether the current user has the read permission

-w Tests whether the current user has the write permission

-x Tests whether the current user has the execution permission

-l Tests whether a file is a symbolic link (soft link file)

Example: [-f /opt/abc.txt]

2. Comparison of integer values in shell

Integer comparison refers to the determination of the relationship between two given integer values: for example, whether they are greater than, equal to, less than…

[Integer variable 1 operator integer variable 2]

2.1. Operators

— -eq: The first number is Equal to the second

– -ne: the first number is Not Equal to the second

– -gt: the first value is Greater Than the second value

– -ge: the first number is Greater or Equal to the second number

-lt: The first number is Lesser Than the second

– -le: the first term is less than or Equal to the second term

3. String comparison

3.1. Common operators

– – = : The characters contain the same contents

– -! = : Different string contents! The sign means the opposite

— z: The string content is empty

— n: Indicates whether the character exists

Format:

[” string 1″ = “string 2″] or [” string 1″ ==” string 2″]

[” string 1″!= “string 2”]

[-z “string”] -z: Checks whether the string is empty or the specified variable is null

[-n “string”] -n: Checks whether the string exists

3.2 Floating point numerical operations

1, the echo “string” of floating point calculation | BC

Awk ‘BEGIN {print string} ‘

4. Logical operation

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

Or – o or | | : logic, the meaning of “or” a true is true Just before and after the condition of an established

-! :

[expression 1] && [expression 2] is equivalent to [expression 1 -a expression 2] [[expression 1 && expression 2]]

Expression [1] | | expression [2] is equal to 1-2 o expression [expression] [[expression 1 | | expression 2]]

5. Ternary operators

Java, c environment:

Conditional expression? a:b

When the conditional expression is true, the value of A is taken; When the conditional expression is false, take the value b Shell script:

[expression] && | a | b

If the expression is true take a value: otherwise take b value

6. If conditional statement

6.1. Single branch

If [expression]; then

.

Fi

6.2. Double branches

If [expression]; then

.

else

.

fi

6.3. Multiple branches

If [expression]; then

.

Elif [expression]; then

.

Elif [expression]; then

.

[else]

fi

7. Case statement

In case variables

Model 1)

.

;;

Model 2)

.

;;

.

*)

.

esca