Conditions test statement and Shell condition test statement in Shell
Shell has conditional test statements. Generally, the test or [] commands are used to complete the test. They are conditional judgment statements if ~ The basis of the then statement, especially the [] command. The following describes some conditional test statements.
1. test command to implement conditional test
The test command is useful when detecting whether certain files exist in the system or related attributes.
The basic syntax is as follows:
The test command can also test the string:
The test command can also test the relationship between integers:
2. [] command to implement conditional Testing
Pay special attention to the use of the [] command in brackets to implement the conditional test function. Because brackets are useful in many places, such as wildcards and regular expressions. When [] is used for conditional testing, we must follow the following principles:
1) Each component in [] must be separated by a space key, for example, [□" $ HOME "□= □" $ MAIL" □]
2) the variables in brackets should be enclosed in double quotation marks;
3) constants in brackets are enclosed in single or double quotation marks.
[] Command to implement conditional testing is generally used for if ~ In the condition judgment Statement of then.
Refer:
Laruence's Linux private house dish