首页 > 系统服务 > 详细

shell script 之六:循环 while

时间:2018-03-22 14:54:36      阅读:273      评论:0      收藏:0      [点我收藏+]

while循环

基本语法:

while <条件>
do
    <命令>
done

while循环更多地用于读取标准输入的内容来实现循环

 

例1:依次打印数字

#!/bin/bash
#while test
#by sunny
i=10
while ((i<100));
do
sleep 1
  echo "the num is $i"
  ((i++))
  if [ $i -gt 15 ];then    # i超过15会停止循环跳出
    break
  fi
done

执行 sh while1.sh 
the num is 10
the num is 11
the num is 12
the num is 13
the num is 14
the num is 15

  



  

shell script 之六:循环 while

原文:https://www.cnblogs.com/sunny18/p/8623791.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!