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里面表达式的计算,可以有 ...
随机推荐
- python 自动化-"Elements not visible"
一,今天试着跑一个多乘客下单的python脚本, 总是遇到 Elements not visible 或者 not clickable的错误 解决方法: 1. 首先观察脚本运行时, 报错的那个元素 ...
- 开发react的一些记录
1.keyboard事件返回的对象SyntheticKeyboardEvent全部是null 解决方法:SyntheticKeyboardEvent的type,which,timeStamp可以得到你 ...
- 【page.js】配置及Page函数说明
页面.js中的Page函数用来注册一个页面,指定页面的初始数据.生命周期回调.事件处理函数等. 语法:Page(Object)参数: Object json对象 Page({ /** * data * ...
- Visual Studio各版本工程文件之间的转换 [转载]
原网址:http://www.cnblogs.com/jmliao/p/5594179.html Visual Studio各版本工程文件之间的转换 由于VS版本比较多,低版本无法直接打开高版本的 ...
- UVA 11884 A Shooting Game(记忆化搜索)
A and B are playing a shooting game on a battlefield consisting of square-shaped unit blocks. The bl ...
- w命令集合
startx:在命令行模式下输入会进入图形界面 exit:注销Linux(以login shell登录会注销账号,以non-login shell登录会退出终端) data:显示日期和时间 data ...
- DFS——CodeForces740DAlyona and a tree
一.题目回顾 题目链接:Alyona and a tree Examples Input 52 5 1 4 61 71 13 53 6 Output 1 0 1 0 0 Input 59 7 8 ...
- NO3——BFS
#include <stdio.h> #include <string.h> #include <queue> using namespace std; struc ...
- video on web
一.video容器 你可能经常看到.avi或.mp4的视频文件,实际上avi或者mp4只是一种视频容器.打个比方,ZIP的压缩文件可以包含各种各样的文件,同理,视频容器也定义用来怎么存放各种 ...
- mysql 数据包太小会引发错误信息
Error querying database. Cause: com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for quer ...