shell脚本第三篇------for循环和while循环

for循环结构 格式:  

for循环格式:
              for 变量名 in 列表
              do
                  语句
              done

命令: seq start size max
         start: 开始点
         size:  间隔,步长   size为1的时候可以省略
         max: 结束点

案例: 输出1-10之间的数
shell脚本:
           
 结果:
          


改进版: 使用命令的方式控制数字的范围
shell脚本: 
          
                
结果:
        
 

while循环: 格式

while [ 条件 ]
do 
命令
done 

案例 :求1-100的和

 变量间加减运算:            s=$(($s+$i))  都是把相当于  sum=sum+i
                                        s=$[$s+$i] 
                                         ((s=$s+$i))  
shell脚本:
                                           
结果:
              
           


 

发布了106 篇原创文章 · 获赞 11 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/object_oriented_/article/details/88578889