用户登录  |  用户注册
首 页文章中心源码下载绿色软件动画频道河源问吧最新软件软件排行最新源码源码排行
当前位置:河源下载站文章中心操作系统Linux
日期:2006-07-19 01:19:42  来源:www.cngr.cn

Shell编程(转载)

结果如下:
xx
yy

yy
zz

5. for语法以及流程图如下

│ FALSE
for var ┌—<参数中还有东西吗?>—┐
do │ │TRUE │
commands │ 从参数中取得一项 │
done │ 放到变数var │
│ │ │
│ commands │
└—————┘ │
档名:lstarg ┌—————┘
┌———————————┐ │
│for a │
│ do │
│ echo $a │
│done │
└———————————┘
$lstarg xx yy zz
xx
yy

yy
zz

6. while 语法以及流程图如下


│ FALSE
while (condition) ┌—<condition>—┐
do │ │TRUE │
commands │ commands │
done └————┘ │
┌————┘


┌———————————————┐
│number=0 │
│while (test $number -lt 10) │
│ do │
│ echo "$number\c" │
│ number=`expr $number + 1` │
│done │
│echo │
└———————————————┘
结果如下:
0123456789

7. until语法以及流程图如下


│ TRUE
until (condition) ┌—<condition>—┐
do │ │FALSE │
commands │ commands │
done └————┘ │
┌————┘


它和while 的不同只在於while 是在条件为真时执行回圈,而until 是在条件 为假时执行回圈。

8. break及continue
这两者是用於for, while, until 等回圈控制下。break 会跳至done後方执行 ,而continue会跳至done执行,继续执行回圈。

9. case语法以及流程图如下

│ TRUE
case str in <str=pat1>————commands1—┐
pat1) commands1;; │FALSE TRUE │
pat2) commands2;; <str=pat2>————commands2—┤
pat3) commands3;; │FALSE TRUE │
esac <str=pat3>————commands3—┤
│FALSE │
├————————————┘


而pat 除了可以指定一些确定的字串,也可以指定字串的集合,如下
* 任意字串
? 任意字元
[abc] a, b, 或c三字元其中之一
[a-n] 从a到n的任一字元
| 多重选择

┌———————————————┐
│echo 'Enter A, B, or C: \c' │
│read letter │
│case $letter in │
│ A|a) echo 'You entered A.';;│
│ B|b) echo 'You entered B.';;│
│ C|c) echo 'You entered C.';;│
│ *) echo 'Not A, B, or C';; │
│esac │
└————————

上一页  [1] [2] [3] 

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
Copyright © 2003-2008 Cngr.CN. All Rights Reserved .