用bash写一个累加程序

来源:百度知道 编辑:UC知道 时间:2024/06/06 15:09:37
如题 从键盘输入一个字数n
然后实现从一到n的累加
谢谢啦啦

#!/bin/bsah
echo "enter a number:"
read n
sum=0
while [ $n -gt 0 ]
do
let sum=sum+n
let n=n-1
done
echo "result=$sum"

#!/bin/bash
n=1
sum=0;
echo -n "input a number n: "
read n
while [ $n -gt 0 ]
do
let sum+=n
let n--
done
echo "the sum is "$sum
exit 0

这个用按键精灵很好作的~~~~~~~~~去下一个把