First Category: Digital cycle
-----------------------------
for1-1.sh
#!/bin/bash for ((i=1; i<=; i++)); do Echo $ (expr31); Done
-----------------------------
for1-2.sh
#!/bin/bash for with $ (seq1) do Echo $ (expr31); Done
-----------------------------
for1-3.sh
#!/bin/bash for in {1.. Ten } do Echo $ (expr31); Done
-----------------------------
for1-4.sh
#!/bin/bash awk'begin{for (i=1; i<=10; i++) Print i}'
Type II: Character loops
-----------------------------
for2-1.sh
#!/bin/bash for in 'ls'; do Echo file name\! ; Done
-----------------------------
for2-2.sh
#!/bin/bash for in $* ; do echo $i is input chart\! ; Done
-----------------------------
for2-3.sh
#!/bin/bash for in F1 F2 F3; do Echo $i is appoint; Done
-----------------------------
for2-4.sh
#!/bin/bash list="rootfs usr data data2" for inch $list; do Echo $i is appoint; Done
Class III: PATH Lookup
-----------------------------
for3-1.sh
#!/bin/bash forfile in/proc/*; Do echo $file is file path \!; Done
-----------------------------
for3-2.sh
#!/bin/bash forfile in $ (ls *. SH) do echo $filefile path \! ; Done
Summarize:
It is now common to use a for-in structure, in which a function can be used to construct a range, such as $ () and ' these, which write some lookup syntax, such as LS test*, then the output file name after the traversal.
Reference:
HTTP://BLOG.CSDN.NET/BABYFISH13/ARTICLE/DETAILS/52981110 (the above content is transferred from this article)
A For loop statement for the shell under Linux