Directory:
I. While loop and until loop
Two. Loop control statement continue break shift
Three. Special usage
I. While loop and until loop
- 1.while Cycle
While CONDITION; Do
Loop body
Done
CONDITION: cyclic control condition; Before entering the loop, make a judgment first; once again, each cycle is judged again; if the condition is true, a loop is executed until the condition test state is a false termination loop.
2.until
Until CONDITION; Do
Loop body?
Done
The Until loop is opposite to the while loop condition: The loop control condition is false, then a loop is executed, until the condition test state is true to terminate the loop.
Example: Displaying 1-5 of the numbers
#!/bin/bash n=0 while [ $n -lt 5 ];do let n=$n+1 echo $n done
- Until notation
#!/bin/bash
N=0
Until [$n-eq 5];d o
Let n= $n +1
Echo $n
Done two. loop control statementsContinue break shift
* 1.continue[n]: End of the first N layer of the current cycle, and directly into the next round of judgment; the inner layer is the 1th floor.
While CONDTIITON1; Do
CMD1 ...
if CONDITION2; Then
Continue
Fi
Cmdn
...
Done
2.break [n]: Early end of the nth layer cycle, the inner layer is the 1th layer
While CONDTIITON1; Do
CMD1 ...
if CONDITION2; Then
Break
Fi
Cmdn
...
Done
Let's make a few changes to the first example in which we add continue and break
#!/bin/bash
N=0
While [$n-lt 5];d o
Let n= $n +1
If [$n-eq 3];then
Continue
Fi
Echo $n
Done
Output of 1245 when adding continue
#!/bin/bash n=0 while [ $n -lt 5 ];do let n=$n+1 if [ $n -eq 3 ];then break fi echo $n done
- The result of joining break is 12
Thus it can be concluded that the difference between the two is that continue is the end of the wheel cycle
Break is the end when the layer loops
3.shift [n] is used to move the list of parameters to the left for a specified number of times, and the default is to move left once. Parameter list once moved, the left-most argument is removed from the list.
The while loop of the shell script