1. If
Syntax format for IF
if Conditon Then Command1 command2 " commandnfi
2. If Else
if Conditon Then Command1 command2 " commandnelse Command1 Command2 "' commandnfi
3. If ElseIf else
if Conditon Then Command1 command2 " commandnElseif conditon Command1 Command2 ' commandnelse command1 command2 ' CommandNfi
4. For loop
for inch item1 item2 item3) Do Command1command2 ' CommandN Done
5. While
while condition Do Command1 command2 "' commandndone
6, until
The Until loop executes a series of commands until the condition is true.
until condition Do commanddone
7. Case
The Shell Case statement is a multi-select statement. A case statement can be used to match a value with a pattern, and if the match succeeds, the matching command is executed. The case statement is in the following format:
Case inch mode 1) Command1 command2 ... CommandN ;; Mode 2) Command1 command2 ... CommandN ;; Esac
8. Break
The break command allows you to jump out of all loops (all loops after the execution is terminated).
In the following example, the script enters a dead loop until the user enters a number greater than 5. To jump out of this loop and return to the shell prompt, you need to use the break command.
#!/bin/Bash while : Do Echo-N"Enter a number from 1 to 5:"Read Anum Case$aNuminch 1|2|3|4|5)Echo "the number you entered is $aNum!" ;; *)Echo "the number you entered is not between 1 and 5! Game over"Break ;; EsacDone
Results:Input 1 to 5 3 The number you entered is Span class= "PLN" > 3! input 1 to 5 7
The number you entered is not 1 5 ! Game over
9, continue
The continue command is similar to the break command, with only a little difference, and it does not jump out of all loops and just jumps out of the current loop.
To modify the above example:
#!/bin/Bash while : Do Echo-N"Enter a number from 1 to 5:"Read Anum Case$aNuminch 1|2|3|4|5)Echo "the number you entered is $aNum!" ;; *)Echo "the number you entered is not between 1 and 5!"ContinueEcho "Game Over" ;; Esac Done
Running code discovery, when a number greater than 5 is entered, the loop in the example does not end, and the statement echo " Game Over " is never executed.
Shell Basic Learning (vi) Process Control