kk:
#!/bin/sh
read -p "please input 2 integer:" a b
echo "a=$a,b=$b"
./test9.sh $a $baa:
#!/bin/sh
a=$1
b=$2
sum=0
temp=`expr $a % 2`
if [ "$temp" -eq 1 ]
then
i=$a
while((i<=$b))
do
((sum+=i))
((i+=2))
done
echo "the result1 is $sum"
else
i=$a+1
while((i<=$b))
do
((sum+=i))
((i+=2))
done
echo "the result2 is $sum"
fi
本文介绍了一个使用Shell脚本实现从指定的起始整数开始到另一个整数结束之间的所有奇数进行累加的功能。脚本通过判断输入是否为奇数来决定累加的起点,并使用循环结构完成累加过程。

被折叠的 条评论
为什么被折叠?



