for,while,until

LIST:由空格分隔开的字符串组成

LIST生成方法:

1、整数 {开始..结束},如果是“,”则是单个的变量

image

image

2、整数$(seq 开始 步进 结束)

image

image

3、直接给出

4、glob /etc/*

image

image

5、命令生成

image

image

for:

for 循环条件;do

     循环体

done

 

for var in LIST;do

     循环体

done

while

while 循环条件;do

     循环体

done

条件为时候运行循环体

until

until 循环条件;do

     循环体

done

条件为时候运行循环体

 

循环控制

continue,结束本轮循环

continue n,结束n轮循环

break 跳出循环

break n 跳出n层循环

算术运算

前提:

image

1、$[$A+$B]

image

2、$(($A+$B))

image

3、let $C=$A+$B

image

4、expr $A + $B

image

增强型赋值:查看let以查看

+=,-=,*=,/=,++,--

let a++

let a+=3

练习:求100以内整数之和

 

image

结果

image

 

练习:求100以内偶数之和

image

结果

image

练习,打99乘法表

image

结果

image

注意:

echo -n是不换行

-e是启用转移的\

echo不加参数是默认跳下一行