[root@x112 linshi]# cat count2.sh
#!/bin/bash
i=0
while  [ $i -le 100 ]
do
	#let  sum=sum+i
	#sum=$((sum+i))
	sum=$[sum+i]
	let i++
		
done
echo "the count is $sum"
[root@x112 linshi]# sh count2.sh
the count is 5050

 注意:while后面跟的是有返回值的语句,通过$?是否为0,判断循环是否继续执行。 

相关文章:

  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-08
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案