编写一个shell脚本程序,从命令行输入10个数

编写一个shell脚本程序,从命令行输入10个数,当输入的数中包含0或负数时输出error,同时将错误信息保存到/tmp/err文件,否则,输出这10个数的乘积

#!/bin/bash
all=$*
if [ $# -ne 10 ];then
        echo error|tee -a /tmp/err
        exit 1
fi
sum=1
for i in $all
do
        if [ $i -le 0 ];then
                echo error|tee -a /tmp/err
                exit 1
        else
                sum=`expr $sum \* $i`
        fi
done
echo $sum

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网