#数字段形式
For i in {1..10}
Do
Echo $i
Done
#详细列出 (characters and not many items)
For File in 1 2 3 4 5
Do
Echo $File
Done
#对存在的文件进行循环
For shname in ' LS *.sh '
Do
Name= ' echo ' $shname | Awk-f. ' {print '} '
Echo $name
Done
#查找循环 (This method can also be used when the LS data is too large)
For Shname in ' find. -type f-name "*.sh"
Do
Name= ' echo ' $shname | awk-f/' {print $} '
Echo $name
Done
# (Syntax loop--a bit like C syntax, but remember the double parenthesis
For ((i=1;i<100;i++))
Do
if ((i%3==0))
Then
Echo $i
Continue
Fi
Done
#seq形式 starting from 1
For i in ' SEQ 100 '
Do
if ((i%3==0))
Then
Echo $i
Continue
Fi
Done
#while循环注意为方括号 [], and note the space
Min=1
max=100
While [$min-le $max]
Do
Echo $min
min= ' expr $min + 1 '
Done
#双括号形式, the internal structure is a bit like the C syntax, note assignment: i=$ (($i + 1))
I=1
while (($i <100))
Do
if (($i%4==0))
Then
Echo $i
Fi
i=$ (($i + 1))
Done
# Loop Control Statements
The # Break command does not perform the current loop within the body break, and the following statement exits from the current loop.
# Continue command is a program that ignores the following statement in this body, starting from the loop header
Shell for, while usage