linux基本操作---shell编程之 while循环
来源:互联网 发布:yy静态头像psd源码 编辑:程序博客网 时间:2024/06/15 11:26
java中我们经常用到while循环,那么shell中也有while循环:
while简单循环
直接看demo:
demo1: 求1-10的和
[root@dev-02 software]# cat while1to10.sh #!/bin/bashi=1while [ $i -le 10 ]do sum=$((sum+i)) i=$((i+1))doneecho $sum[root@dev-02 software]# sh while1to10.sh 55
问题:
开始的时候 老是报错,我们的写法是
报错:[root@dev-02 software]# sh while1to10.sh while1to10.sh: line 3: while[1 -le 10]: command not foundwhile1to10.sh: line 4: syntax error near unexpected token `do'while1to10.sh: line 4: `do'脚本:[root@dev-02 software]# cat while1to10.sh #!/bin/bashi=1while[$i -le 10]do sum=$((sum+i)) i=$((i+1))doneecho $sum之后修改while的参数之间需要用空格隔开,问题解决,这个语法真6,无语了,苦笑。
while读取文件内容:
读取文件,遍历every line ,有next line ,就echo line
[root@dev-02 software]# cat readwhile.sh #!/bin/bashwhile read -r linedo echo $linedone < /etc/passwd[root@dev-02 software]# sh readwhile.sh root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologin...
关于-r 我们看一下帮助文档,可以发现-r是不考虑转义字符。
-r Backslash does not act as an escape character. The backslash is considered to be part of the line. In par-
ticular, a backslash-newline pair may not be used as a line continuation.
阅读全文
0 0
- linux基本操作---shell编程之 while循环
- Linux shell 编程之while循环、until循环
- linux shell编程while循环
- Linux 下的 shell 编程之 while 循环
- linux 下的Shell编程之while、until循环
- Shell脚本编程之While循环
- linux基本操作---shell编程 for循环(99乘法表)
- Linux Shell系列教程之(十一)Shell while循环
- linux shell编程学习--循环流程while,for,until命令
- shell 脚本之 while 循环
- Linux之Shell脚本while循环ssh登录执行命令
- linux之while循环
- Linux shell编程之for循环
- linux 下shell编程之for循环
- Shell编程之数组、字符串基本操作
- Shell 编程7(循环语句while)
- 【shell编程学习】for 和 while循环
- shell脚本编程举例--for、while循环
- 创业需要解决的几个问题
- MARK
- Phpcms V9 各类页面调用文章点击量及评论数量方法
- 设计模式之组合模式
- JavaSE 反射 Part6
- linux基本操作---shell编程之 while循环
- java springboot常用注解
- SublimeServer插件安装和使用
- ionic3学习笔记(四)
- UITableView 的使用
- 正弦信号发生器设计制作经验教训
- 【解题报告】poj openjudge 拼写检查 pku数算mooc 检索
- 申请腾讯云服务器
- Java | 接口和抽象类