实现shell四则运算

来源:互联网 发布:ubuntu vi命令 编辑:程序博客网 时间:2024/05/29 14:31
#!/bin/bash#if [ $# -lt 3 ];then   echo "para err."   exit 1fiif [ "$2" == "/" ];then   result=`echo "scale=2;$1/$3;" | bc`    echo $resultelif [ "$2" == "+" ];then   result=`echo "scale=2;$1+$3;" | bc`    echo $resultelif [ "$2" == "-" ];then   result=`bc <<< "scale=2;$1-$3;"`    echo $resultelif [ "$2" == "*" ];then   result=`echo "scale=2;$1*$3;" | bc`   echo $resultelse    echo "opt err."fi
0 0
原创粉丝点击