首页 > 系统服务 > 详细

Shell编程 之 while循环 和 until循环 和 总结

时间:2017-02-12 18:59:16      阅读:285      评论:0      收藏:0      [点我收藏+]

1. while 循环

  1.1 语法结构

    技术分享

  1.2 案例:从1加到100

#!/bin/bash

i=1
s=0

while [ $i -le 100 ]
        do
                s=$(( $s+$i ))
                i=$(( $i+1 ))
        done
echo "the result is: $s"
~                                                                                  
~                                                                                  
~                                                                                                                                                                    
"while1.sh" 11L, 111C

2. until 循环

  2.1 语法结构

    技术分享

  2.2 案例:从1加到100

#!/bin/bash

i=1
s=0

until [ $i -gt 100 ]
        do
                s=$(( $s+$i ))
                i=$(( $i+1 ))
        done
echo "the result is: $s"
~                                                                                  
~                                                                                  
~                                                                                                                                                                   
"until1.sh" 11L, 111C

3. 课程总结

  - shell 主要用来简化管理员操作

  - shell 编程更多的考虑程序的功能实现,而不是效率

  - Apache 启动脚本:/etc/rc.d/init.d/httpd

Shell编程 之 while循环 和 until循环 和 总结

原文:http://www.cnblogs.com/wnzhong/p/6391408.html

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