Article Directory
for loop
format
for 变量名 in 取值列表
do
命令序列
done
Three different formats of variable i
for i in { } 用法
for i in $(seq 1 10)
Supplement: $(seq 1 2 10)
for ((i=1;i<=10;i++))
Instance
Check the host status according to the IP address. The
IP address is stored in the ipadds.txt file, one per line.
Use the ping command to check the connectivity of each host
while statement
format
while 条件测试操作
do
命令序列
done
Format example
Instance
Guess the commodity price game
Obtain a random number through the variable RANDOM.
Prompt the user to guess and record the number of times. After the guess is successful , exit the loop
until statement
format
until 条件测试操作
do
命令序列
done
Test a certain condition repeatedly, and execute it repeatedly as long as the condition is not established
Double loop
break out of the loop
break out of the two-layer loop
continue to abort a command in a loop, but not completely abort the entire command
IFS field separator
Contains spaces, tabs, and newlines by default
Instance