#!/基郑bin/bash
multiply()
{
if [ $1 -gt 1 ]then
result=`expr $result \* $1`
next=`expr $1 - 1`
multiply $next
fi
}
if [ $# -ne 1 ]then
echo -e "Please input a parameter!\nUsage: $0 [n]"
exit 1
fi
result=1
if [ $1 -eq 1 ]then
:
elif [ $1 -gt 1 ]then
multiply $1
else
echo "Invalid input parameter! It MUST be a integer greater than 0."
exit 1
fi
echo "$1! = $result"
exit 0
#!/梁枝哪bin/bashecho "$*" | sed 's/ //g' | egrep "^[0-9]+$" >/dev/null 2>&1
if [[ $# -eq 0 || $? -gt 0 ]]then
echo "Usage:./test.sh 参搭颂数(只允许是整橡码数)"
exit 1
fi
sum1=0
sum2=1
until [ $# -eq 0 ]do
sum1=$(echo "$sum1+$1" | bc)
sum2=$(echo "$sum2*$1" | bc)
shift
done
echo "和 is: $sum1"
echo "乘积 is: $sum2"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)