0
更新:乘号如果被当作参数输入,默认占用四个参数位,所以这个脚本是不完美的,因为做不了乘法运算
#!/bin/bash
if [ $# -ne 3 ]
then
echo "please input the first parameter number between 0 to 9"
echo "please input the second parameter as one of below + - * / %"
echo "please input the third parameter number between 0 to 9"
exit 1
fi
a=`echo $1|sed 's/[0-9]//g'`
b=`echo $3|sed 's/[0-9]//g'`
if [ -n "$a" -o -n "$b" ]
then
echo "please input number between 0 to 9"
exit 1
fi
echo "scale=2;$1$2$3"|bc
编辑回复