Select Execute
Fi
A. Conditional Select if statement, can be nested
B. Format
Single Branch
if judgment condition; then
Condition is true
Fi
Dual Branch
if judgment condition; then
Condition is true
Else
Condition is False
Fi
Multi-Branch
if judgment condition; then
Condition is true
Elif (equivalent to else if) to determine the condition; then
Condition is true
Else
All of the above conditions are false
Fi
The first time a true condition is encountered, the branch is executed and fi ends the entire if statement.
Take a look at a few examples to find out exactly what the format is in the script.
After all the scripts have been written, the actions are the same, and they are shown here once.
Case
A.case supports GLOB-style wildcard characters
* |
Any character of any length |
? |
Any single character |
[ ] |
Any single character within the specified range |
A|b |
A or B |
B. Format
Case variable reference in
PAT1) Branch;;
PAT2) Branch;;
...
*) Branch;;
Esac
Loop execution
Definition: run a code segment repeatedly, with entry conditions and exit criteria
For
A. Format
For variable name in assignment list;
Loop body
Done
B. Execution mechanism: assigns the element of the list to the variable name sequentially, executes the loop body once each assignment, knows that the list is exhausted, and the loop ends
C. How the list is generated
(1) The list is given directly.
(2) List of integers
(a) {1..10}
(b) $ (SEQ 1 10)
(3) return list of commands $ (cmd)
(4) variable reference [email protected],$#
While
A. Format
While loop control condition; do
Loop body
Done
B. The loop control condition is true, enter the loop, otherwise exit the loop
c. Special usage Traverse each line of a file
While Read Line;do
Loop body
Done < filename
Read each line of the file sequentially, and assign the value to $line
Until
A. Format
until cyclic control conditions; do
Loop body
Done
B. loop control condition is false, enter loop, otherwise exit loop
Continue
Used in the loop body, to end the first n layer of this round cycle, into the next round of n+1 layer cycle
Break
Used in the loop body, to end the N-level round cycle in advance
The two are applied in other loop statements, and in the pictures of the other examples.
Shift
Shift N
Used for parameter list, left shift specified number of times, not specified as left shift, once moved, left-most parameter removed from list
Select used to create menus
A. Format
Select variable in List;do
Circular Body Command
Done
B.PS3 prompt
C. Enter a number in the menu, execute the corresponding command, is the wireless loop, you need to break out of the loop or exit to terminate the script