码迷,mamicode.com
首页 > 其他好文 > 详细

循环语句

时间:2015-02-01 17:30:43      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

1.while循环

while语法:
http://codingstandards.iteye.com/blog/780524
===================输出1到20
[root@lvm ~]# cat while.sh
#!/bin/bash
i=1
while [ $i -le 20 ]
do
echo $i
let i++


done
===

================= 累加
[root@lvm ~]# cat while.sh
i=1
while ((i<=20))
do
touch $i
echo $i file create ok
let i++
done
===

======================死循环
[root@lvm ~]# cat while.sh
#!/bin/bash
i=1
while [ 1 ];do
echo $i
let i++
done
===

======================同上
#!/bin/bash
i=1
while file /etc/hosts ;do #file /etc/hosts 只是一个判断条件
echo $i
let i++
done


2.for循环

for语法
==========================输出1到$num
#!/bin/bash
#for i in {1..20}
read -p "please key in number:" num
for i in `seq $num`
do
echo $i
done
===

=====================================
###for循环给循环赋初始值
for i in `seq 1 1000000`;do
echo $i
done
======================================

 

循环语句

标签:

原文地址:http://www.cnblogs.com/blog-acf/p/4265660.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!