编写一个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
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
温馨提示:答案为网友推荐,仅供参考