Linux shell 编程之while循环、until循环
来源:互联网 发布:mac的pages怎么保存 编辑:程序博客网 时间:2024/05/23 20:29
一、while循环
while命令也可以用来实现循环
基本格式如下:
while test commanddo commandsdone若test command条件判断成立,则执行commands,若不成立,则跳出循环。
$ cat test.sh#!/bin/basha=1while [ $a -le 10 ]do echo "a=$a" a=$[$a+1]done$ ./test.sha=1a=2a=3a=4a=5a=6a=7a=8a=9a=10while命令有个奇怪的用法,while命令允许在while语句行定义多条命令,但是只有最后一条测试命令的退出状态 决定循环是否停止。
$ cat test.sh#!/bin/basha=1while echo $a [ $a -le 10 ] do echo "a=$a" a=$[$a+1]done$ ./test.sh1a=12a=23a=34a=45a=56a=67a=78a=89a=910a=1011注意最后一行打印出了"11",之后 判断 条件[ $a -le 10 ]不成立,然后退出循环。
二、until循环
until命令也可以用来实现循环,基本格式:
until test commanddo other commandsdone与while命令恰恰相反,若test command条件判断不成立,则执行commands,若成立,则跳出循环。until命令在until语句行也可以定义多条命令,只有最后一条测试命令的退出状态。
$ cat test.sh#!/bin/basha=1until echo $a [ 10 -le $a ] do echo "a=$a" a=$[$a+1]done$ ./test.sh1a=12a=23a=34a=45a=56a=67a=78a=89a=910
0 0
- Linux shell 编程之while循环、until循环
- linux 下的Shell编程之while、until循环
- linux shell编程学习--循环流程while,for,until命令
- shell之循环 (for、while、until)
- shell 脚本之for while until循环
- shell for循环,while循环,until循环
- 【bash】编程之for,while,until循环
- shell编程-流程控制-while循环与until循环
- Linux shell学习(六)while循环 until循环
- shell 循环 for while until ....
- shell循环,for 、while、until
- shell(for、while、until)循环
- Linux 下的 shell 编程之 until 循环
- Shell的while循环和until循环
- Linux学习之while循环与until循环
- Linux Shell系列教程(十三)之Shell while和until循环
- linux shell编程while循环
- shell浅谈之三for、while、until循环
- 引用,类的访问修饰符
- 1023. 组个最小数 (20) PAT 乙级
- 编程思想之多线程与多进程(1)——以操作系统的角度述说线程与进程
- 基础练习-1 十六进制转八进制
- 点分治
- Linux shell 编程之while循环、until循环
- 下拉加载更多DEMO(js实现)
- LINQ读书笔记(一)
- T级数据搜索中值思路
- C语言初级练习
- java多态性
- UML系列图--实现图(构件图 Component 和部署图Deployment)
- Spring cache+ redis与redis 的比较
- 7.5.4