Break, continue, exit, return are generally used to control the direction of the loop
Start with a script description
For ((i=1;i<5;i++))
Do
If [$i-eq 3]
Then
# break
# continue
# exit
Fi
Echo $i
Done
Echo OK
Results of the output
Result of break
1
2
Ok
Results of continue
1
2
4
Ok
Result of exit
1
2
This can explain
Break N/A indicates the number of layers that jump out of the loop, and if n is omitted to jump out of the loop
Continue n-n means to return to the nth level to continue the loop, if omitting n means jumping out of the loop, ignoring the remainder of the loop, and entering the next loop of the loop
Exit N: Exit the current shell program and return to N,n can also omit
Return: returned value of function
Example: Temporarily configure multiple IP addresses for the server and can revoke all IP configurations at any time
IP address: 10.0.0.1-10.10.0.0.16, where 10.0.0.10 cannot be configured
#ifconfig eth0:1 10.10.0.1 netmask 255.255.0.0 up
A simple implementation
For ((i=1;i<=16;i++))
Do
If [$i-eq 10]
Then
Continue
Fi
Ifconfig eth0: $i 10.0.0. $i netmask 255.255.0.0 down
Done
Or
Case "$" in
Start
For ((i=1;i<=16;i++))
Do
If [$i-eq 10]
Then
Continue
Fi
Ifconfig eth0: $i 10.0.0. $i netmask 255.255.0.0 "$"
Done
;;
Stop
For ((i=1;i<=16;i++))
Do
If [$i-eq 10]
Then
Continue
Fi
Ifconfig eth0: $i 10.0.0. $i netmask 255.255.0.0 "$"
Done
;;
*)
echo "usage:$0 [Start|stop]"
Esac
This article is from the "ngames" blog, make sure to keep this source http://ngames.blog.51cto.com/3187187/1537066