1.for循环打印9*9乘法
#!/bin/bash for (( i=1;i<=9;++i )) do for (( j=1;j<=i;++j )) do echo -n "${i}*${j}=$((i*j)) " done echo " " #换行 done
输出结果:
2. 判定一个成绩: 85-100 -》 A 70-84 -> B 60-69 -> C 0-59 ->D 程序的边界问题:>100, <0 必须输入的是数字:0-100
代码如下
score=$1 if [ $score -ge 85 -a $score -le 100 ] then echo “LEVEL A” elif [ $score -ge 70 -a $score -lt 85 ] then echo “LEVEL B” elif [ $score -ge 60 -a $score -lt 70 ] then echo “LEVEL C” elif [ $score -ge 0 -a $score -lt 60 ] then echo “LEVEL D” else echo “wrong score” fi
3.循环创建用户:用户名为user01-user20
for user in seq -f "user%02g" 20 do echo $user done