练习2-从1加到100 Posted on 2020-05-12 In Tutorial , Bash 练习2-从1加到100for循环12345678910111213141516[root@vm-101 ~]# cat lianxi1-100.sh#!/bin/bash# 注释说明,好习惯for (( i=1; i<=100; i++))do sum=$[ $sum + $i ]doneecho $sumexit 0[root@vm-101 ~]# bash lianxi1-100.sh5050 while循环123456789101112131415161718[root@vm-101 ~]# cat lianxi1-100.sh#!/bin/bash# 注释说明,好习惯i=1while [ $i -le 100 ]do sum=$[ $sum + $i ] i=$[ $i + 1 ]doneecho $sumexit 0[root@vm-101 ~]# bash lianxi1-100.sh5050 在升级下1234567891011121314151617181920212223242526[root@vm-101 ~]# cat lianxi1-100.sh#!/bin/bash# 注释说明read -p "输入起始数字:" iread -p "输入结束数字:" endwhile [ $i -le $end ]do sum=$[ $sum + $i ] i=$[ $i + 1 ]doneecho $sumexit 0[root@vm-101 ~]# bash lianxi1-100.sh输入起始数字:10输入结束数字:501230[root@vm-101 ~]# bash lianxi1-100.sh输入起始数字:1输入结束数字:1005050