Shell 实现计算器

话不多说,上代码:
#!/bin/env sh

# Author: BlueMiaomiao
# E-mail: xv2017@outlook.com
# GitHub: bluemiaomiao.github.io
# Desc  : Simple Computer Design

FIR_NUM=`echo $1 | awk -F ‘+|-|*|/‘ ‘{print $1}‘`
SEC_NUM=`echo $1 | awk -F ‘+|-|*|/‘ ‘{print $2}‘`
OPS_SYM=`echo $1 | sed ‘s/[0-9]//g‘`

if [ "$OPS_SYM" == ‘+‘ ]
then
   echo "$FIR_NUM + $SEC_NUM = `expr $FIR_NUM + $SEC_NUM`"
elif [ "$OPS_SYM" == ‘-‘ ]
then
   echo "$FIR_NUM - $SEC_NUM = `expr $FIR_NUM - $SEC_NUM`"
elif [ "$OPS_SYM" == ‘*‘ ]
then
   echo "$FIR_NUM * $SEC_NUM = `expr $FIR_NUM \* $SEC_NUM`"
elif [ "$OPS_SYM" == ‘/‘ ]
then
   if [ "$SEC_NUM" == 0 ]
   then
       echo ‘Params error.‘
   else
       echo "$FIR_NUM ÷ $SEC_NUM = `expr $FIR_NUM / $SEC_NUM`"
   fi
else
   echo ‘Syntax error.‘
fi

Shell 实现计算器

上一篇:ios 中tableview和scrollView的区别


下一篇:跟高手学习LINUX笔记-27--搭建内网用DNS服务器