One, for loop
1. Digital Segment Form
Copy Code code as follows:
For i in {1..10}
Todo
Echo $i
Done
2. Detailed list (character and number of items are not many)
Copy Code code as follows:
For File in 1 2 3 4 5
Todo
Echo $File
Done
3. Circulation of existing documents
Copy Code code as follows:
For shname in ' LS *.sh '
Todo
Name= ' echo ' $shname | Awk-f. ' {print '} '
Echo $name
Done
4. Lookup loop (LS data too large can also use this method)
Copy Code code as follows:
For Shname in ' find. -type f-name "*.sh"
Todo
Name= ' echo ' $shname | awk-f/' {print $} '
Echo $name
Done
5. (Grammar loop--a bit like C syntax, but remember double bracket
Copy Code code as follows:
For ((i=1;i<100;i++))
Todo
if ((i%3==0))
Then
Echo $i
Continue
Fi
Done
6.seq form starting from 1
Copy Code code as follows:
For i in ' SEQ 100 '
Todo
if ((i%3==0))
Then
Echo $i
Continue
Fi
Done
Two, while loops
1.while Circular note for square brackets [], and note that spaces
Copy Code code as follows:
Min=1
max=100
While [$min-le $max]
Todo
Echo $min
min= ' expr $min + 1 '
Done
2. Double bracket form, internal structure somewhat like C syntax, note assignment: i=$ (($i + 1))
Copy Code code as follows:
I=1
while (($i <100))
Todo
if (($i%4==0))
Then
Echo $i
Fi
i=$ (($i + 1))
Done
3. Read from the configuration file and can control the number of processes
Copy Code code as follows:
Max_run_num=8
Cat cfg/res_card_partition.cfg |grep-v ' ^$ ' |grep-v ' # ' | grep-v grep |while Read partition
Todo
Nohup sh inv_res_card_process.sh $partition >log/rescard$partition.log 2>&1 &
While [1-eq 1]
Todo
Psnum= ' Ps-ef | grep "Inv_res_card_process" | Grep-v "grep" | Wc-l '
If [$psNum-ge $MAX _run_num]
Then
Sleep 5
Else
Break
Fi
Done
Done
three. loop control Statement
Copy Code code as follows:
# Break command does not execute the current loop body break the following statement exits from the current loop.
# Continue command is the procedure to ignore the following statements in this body, starting from the loop header