Step 1: Master several if statement branches
The following is the most complete if format. You can delete it as needed in actual use.
If condition; then
// Action
Elif conditon: then
// Action
... Several intermediate Elif
Else
// Action
Then
// Action
Fi
Here are some notes
1. action can be blank
2. If contion; then can also be written
If condion
Then
Step 2: master the conditional writing
Let's take a look at the condition syntax.
In fact, the general conditions are mainly divided into two parts: string and value. A special one in UNIX systems is File Permission detection. You don't have to worry about these comparisons. You can use special commands.
Comparison Commands include:
1. Test
2. expr
Both of them can compare strings and numbers. However, test can also compare certain attributes of files, such as X, W, R, and U.
Next, we will briefly introduce test and expr.
Format: Test condtion or [condtion] (Note that there must be spaces on both sides of square brackets)
Returned value: 0 correct 1 returned error
Usage:
1. Test file attributes: [-X file]
2. String test: = ,! =,-Z,-,-N respectively indicate equal, unequal, empty string, non-empty string
3. Numerical Test:-GT,-lt,-Ge,-Le,-EQ, and-ne respectively indicate greater than, less than, greater than or equal to, less than or equal to, and not equal
Expr is mainly used for integer calculation. It can also be used for numerical comparison and string comparison. The most amazing thing is that it can also be used for pattern matching. [However, I can definitely use awk, sed, or grep instead]
+ ,-,*,/
Note: When Using *, you must add the Escape Character \
Refer:
Http://techbbs.zol.com.cn/1/60_1601.html ###