┌———————————┐
│for a in xx yy zz │
│ do │
│ echo $a │
│done │
└———————————┘
结果如下:
xx
yy
yy
zz
5. for
语法连同流程图如下
│ FALSE
┌—<参数中更有东西吗?>—┐
│ │TRUE │
│ 从参数中取得一项 │
│ 放到变数var │
│ │ │
│ commands │
└—————┘ │
┌———————┘
│
for var
do
commands
done
┌———————————┐
│for a │
│ do │
│ echo $a │
│done │
└———————————┘
$lstarg xx yy zz
xx
yy
yy
zz
6. while
语法连同流程图如下
│ FALSE
┌—<condition>—┐
│ │TRUE │
│ commands │
└————┘ │
┌————┘
│
while (condition)
do
commands
done
┌———————————————┐
│number=0 │
│while (test $number -lt 10) │
│ do │
│ echo "$numberc" │
│ number=`expr $number 1` │
│done │
│echo │
└———————————————┘
结果如下:
0123456789
7. until
语法连同流程图如下
│ TRUE
┌—<condition>—┐
│ │FALSE │
│ commands │
└————┘ │
┌————┘
│
until (condition)
do
commands
done
他和while 的不同只在於while 是在条件为真时执行回圈,而until 是在条件为假时执行回圈。
8. break及continue
这两者是用於for, while, until 等回圈控制下。break 会跳至done后面执行,而continue会跳至done执行,继续执行回圈。
9. case
语法连同流程图如下
│ TRUE
<str=pat1>————commands1—┐
│FALSE TRUE │
<str=pat2>————commands2—┤
│FALSE TRUE │
<str=pat3>————commands3—┤
│FALSE │
├————————————┘
│
case str in
pat1) commands1;;
pat2) commands2;;
pat3) commands3;;
esac
而pat 除了能够指定一些确定的字串,也能够指定字串的集合,如下:
* 任意字串
? 任意字元
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




