Shell中的while循环【转】
- while expression
- do
- command
- command
- ```
- done
- 1 #!/bin/sh
- 2 int=1
- 3 while(( $int<=5 ))
- 4 do
- 5 echo $int
- 6 let "int++"
- 7 done
- 1 #用脚本演示使用结束标记控制while循环实现猜1~10内的数
- 2 #!/bin/sh
- 4 echo "Please input the num (1~~10): "
- 5 read num
- 6 while [[ $num != 4 ]]
- 7 do
- 8 if [ $num -lt 4 ]
- 9 then
- 10 echo "Too small ,Try again.."
- 11 read num
- 12 elif [ $num -gt 4 ]
- 13 then
- 14 echo "Too big ,Try again.. "
- 15 read num
- 16 else
- 17 exit 0
- 18 fi
- 19 done
- 20 echo "Yes ,you are right !!"
- 1 #!/bin/sh
- 2 echo "Please input the num:"
- 3 read num
- 4 sum=0
- 5 i=1
- 6 signal=0
- 7 while [[ $signal != 1 ]]
- 8 do
- 9 if [ $i -eq $num ]
- 10 then
- 11 let "signal=1"
- 12 let "sum+=i"
- 13 echo "1+2、、、+$num=$sum"
- 14 else
- 15 let "sum=sum+i"
- 16 let "i++"
- 17 fi
- 18 done
- 1 #!/bin/sh
- 3 echo "Please input arguements is $# "
- 4 echo "What you input : "
- 5 while [[ $* != "" ]]
- 6 do
- 7 echo $1
- 8 shift
- 9 done
Shell中的while循环【转】的更多相关文章
- shell编程学习笔记(十):Shell中的for循环
shell编程中可以实现for循环遍历 先来写一个最简单的吧,循环输出从1到10,脚本内容为: #! /bin/sh for i in {1..10} do echo $i done 上面的代码从1到 ...
- shell中的for循环用法详解
for i in “file1” “file2” “file3”for i in /boot/*for i in /etc/*.conffor i in $(seq -w 10) –>等宽的01 ...
- shell 中可以for 循环的时间加减日期格式
..};do # LAST_HOUR=`date -d '-${num} hour' +%H` 不可for循环,报格式错误 LAST_HOUR=`date "+%H" -d -${ ...
- Shell中的while循环
while循环的格式 while expression do command command ``` done 1.计数器控制的while循环 主要用于已经准确知道要输入的数据和字符串的数目 ...
- shell 中的for循环
第一类:数字性循环 #!/bin/bash for((i=1;i<=10;i++)); do echo $(expr $i \* 3 + 1); done #!/bin/bash for i i ...
- shell中for循环总结
关于shell中的for循环用法很多,一直想总结一下,今天网上看到上一篇关于for循环用法的总结,感觉很全面,所以就转过来研究研究,嘿嘿... 1. for((i=1;i<=10;i++));d ...
- 02: shell中的if、case、for等语句
目录: 1.1 shell中常用运算符 1.2 使用if条件语句 1.3 shell 中的for循环 1.4 shell中的while循环语句 1.5 使用case分支语句 1.1 shell中常用运 ...
- MongoDB 学习笔记(二):shell中执行增删查改
一.查 1.查询集合中所有文档:db.集合名.find(). 2.查询集合中第一个文档:db.集合名.findOne(). 3.指定查询条件:第一个参数就是指定查询条件 查询全部文档:db.集合名.f ...
- shell中的循环
shell中的循环 for循环 类似于C语言的步长控制 例如: ;i<=;i++)); ); done 将1到10,依次乘以4,然后打印出来. 这里顺便提一下,shell里面表达式的计算,可以有 ...
随机推荐
- 【java并发编程实战】第五章:基础构建模块
1.同步容器类 它们是线程安全的 1.1 vector和hashtable. 和Collections.synchronizeXxx()一样.实现方式就是在每个方法里面加入synchronize代码块 ...
- wpf显示视频,image控件闪屏,使用winform控件实现
使用C#调用mingw的动态库实现视频识别软件,程序通过C++调用opencv打开视频,将图像的原始数据以rgb24的方式传递给C#端,C#通过构造图像对象给控件赋值的方式显示图片. 一开始使用wpf ...
- python 面试题: 列表表达式
[process() for item1 in iterable1 if condition1 for item2 in iterable2 if condition2 For item3 in it ...
- gdb coredum 信息例子
http://blog.csdn.net/hzhsan/article/details/38227647
- 持久化ORM框架——Hibernate与mybatis
最初SUN公司推出了JavaEE服务器端组件模型(EJB),但是由于EJB配置复杂,且适用范围较小,于是很快就被淘汰了.与EJB的失败伴随而来的是另外一个框架的应运而生.他就是至今也比较流行的Hibe ...
- OpenCV漫水填充算法示例代码
#include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplImage* img = cvL ...
- [剑指Offer] 23.二叉搜索树的后序遍历
[思路]BST的后序序列的合法序列是,对于一个序列S,最后一个元素是x (也就是根),如果去掉最后一个元素的序列为T,那么T满足:T可以分成两段,前一段(左子树)小于x,后一段(右子树)大于x,且这两 ...
- input属性 disabled与readonly的区别
从效果上看 源码 <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...
- Codeforce 721C DP+DAG拓扑序
题意 在一个DAG上,从顶点1走到顶点n,路径上需要消费时间,求在限定时间内从1到n经过城市最多的一条路径 我的做法和题解差不多,不过最近可能看primer看多了,写得比较复杂和结构化 自己做了一些小 ...
- 【CF edu 30 A. Chores】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...