Basic shell syntax in CentOS
1. Sorting command
Sort option file name
-F case-insensitive
-N is ordered by numeric values (string type by default)
-R reverse sorting
-T specifies the delimiter (Tab by default)
-Kn [, m] is ordered by the specified range, from n to m (default to the end of the row)
N [, m] can be a single number, for example, 3. A range, for example, 3, 6.
Example:
Sort/etc/passwd
Sort-n-t ":"-k 3, 3/etc/passwd
2. Statistical commandsWc option file name
-L only number of rows
-W: Number of words only
-M: Only characters
3. if condition judgment statementIf [condition Judgment]; then
Program
Fi
Or
If [condition determination]
Then
Program (condition is true)
[Else
Another program (the condition is not true)]
Fi
Or
Multi-branch if
If [condition judgment 1]
Then
Procedure 1
Elseif [condition Judgment 2]
Then
Procedure 2
.........
.........
Else
(If none of them are available, execute this operation)
Fi
4. case statementCase $ variable name in
"Value 1 ")
Procedure 1
"Value 2 ")
Procedure 2
;;
.........
.........
*)
If it is not the above value, execute this program
;;
Esac
5. for statement1)
For variable in value 1 value 2 ......
Do
Program
Done
2)
For (initial value; cyclic control conditions; variable changes ))
Do
Program
Done
6. while and until statementsWhile [conditional criterion]
Do
Program
Done
Until stands for "until", opposite to "while", that is, as long as the conditional condition is not true, the loop is executed and the loop program is executed. Once the loop condition is true, the loop is terminated. The format is the same as while.
7. Condition judgmentThe format is as follows: add the judgment command in brackets [absolute path of the Option file]
Determine by file type
Judge by File Permission
Compare two files
Comparison between two integers
String judgment
Multi-condition judgment
I will not give an example of conditional judgment, but the importance of conditional judgment is self-evident!