Unix系列shell程序编写(中)
2009-03-06 14:46
211 查看
8>elif语句 嵌套if语句有时会给用户带来混乱,特别是什么时候fi语句很难判断。因此Bourne Shell又提供了elif语句。elif是else-if的缩写,它表示是if语句的继续。格式为: if command then command elif command then command elif command then command fi 上面介绍的嵌套if语句和elif语句完成相同的功能,用户可以根据自己的喜好选择一种使用。 9>case语句 前面说的elif语句替代if-then-else语句,但有时在编程时还会遇到对同一变量进行多次的测试,该情况可以用多个elif语句实现,但还有一种更简单的方法就是用case语句。 case语句不但取代了多个elif和then语句,还可以用变量值对多个模式进行匹配,当某个模式与变量值匹配后,其后的一系列命令将被执行,下面是case语句使用的语句。 case value in pattem 1) command command;; pattem 2) command command;; .... pattem) command; esac case语句只执行其中的一组命令,当变量值与多个模式相匹配时,只有第一个匹配的模式对应的命令被执行。";;"表示该模式对应的命令部分程序。 通过学习下面的read语句,我们们再举例子说明case语句的用法。 10>read语句 Shell程序不但可以通过命令行参数得到输入数据,还可以使用read命令提示用户输入数据,其语法格式为: read var1 var2... ...varn
相关文章推荐
- Unix系列shell程序编写(下)
- Unix系列shell程序编写4
- Unix系列shell程序编写(上)---
- Unix系列shell程序编写从入门到精通(上)
- Unix系列shell程序编写(下)
- Unix系列shell程序编写
- Unix系列shell程序编写1
- Unix系列shell程序编写(中)
- Unix系列shell程序编写(转)
- Unix系列shell程序编写2
- Unix系列shell程序编写5
- Unix系列shell程序编写(上)
- Unix系列shell程序编写(上)
- Unix系列shell程序编写6
- Unix系列shell程序编写(上)
- Unix系列shell程序编写
- Unix系列shell程序编写(上)
- Unix系列shell程序编写(中)
- Unix系列shell程序编写
- Unix系列shell程序编写3