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

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

原文地址:https://www.cnblogs.com/wnzhong/p/6391408.html