实例(testfor2.sh):
- #!/bin/sh
- for((i=1;i<=10;i++));do
- echo $i;
- done;
while语句构造
- while 前提语句
- do
- action
- done;
实例1:
- #!/bin/sh
- i=10;
- while [[ $i -gt 5 ]];do
- echo $i;
- ((i--));
- done;
运行结不雅:========================
sh testwhile1.sh
9
8
7
6
实例2:(轮回攫取文件内容:)
- #!/bin/sh
- while read line;do
- echo $line;
- done < /etc/hosts;
运行结不雅:===================
sh testwhile2.sh
# Do not remove the following line, or various programs
- for 变量 in seq字符串
- do
- action
- done
# that require network functionality will fail.
127.0.0.1 centos5 localhost.localdomain localhost
- until轮回语句
语法构造:
- until 前提
- do
- action
- done
【编辑推荐】
- 别再笑话Windows了Linux出现“永恒之蓝”进击
- 如何在Linux敕令行下杀逝世一个过程
- 在Linux办事器关机前向用户显示一条自定义消息
- Linux桌面体系的优势
- Linfo:及时显示你的Linux办事器运行状况
意思是:直到知足前提,就退出。不然履行action.
实例(testuntil.sh):
- #!/bin/sh
- a=10;
- until [[ $a -lt 0 ]];do
- echo $a;
- ((a—));
- done;
结不雅:
sh testuntil.sh
8
7
6
5
4
3
2
1
0
三、shell选择语句(case、select用法)
- case选择语句应用(case/esac)
语法构造
- case $arg in
- pattern | sample) # arg in pattern or sample
- ;;
推荐阅读
我们在应用Linux虚拟机的时刻经常会出现各类各样的问题,个中的一个问题就是Linux虚拟机连不上彀,这是我比来经常碰到的问题,下面供给一种办法解决这个问题。 Linux收集设置打开虚拟机依次单击【System】–>>>详细阅读
本文标题:Linux Shell流程控制
地址:http://www.17bianji.com/lsqh/35513.html
1/2 1