#!/bin/bash

####################################################################
# Author:                netcat                                    #
# Lable:                 calc.sh                                   #
# Information:           Simple calculator                         #
# Create Date:           2011-02-21                                #
# Version:               v 1.0                                     #
####################################################################
echo "example: 3 + 5"
read -p "enter:  " a b c
echo $a|grep [a-zA-Z]>/dev/null
if [ $? -ne 0 ];then
echo $c|grep [a-zA-Z]>/dev/null
if [ $? -ne 0 ];then
if [ $b == "+" ]
then
let x=$a+$c
echo "$a + $c = $x"
fi
if [ $b == "-" ]
then
let x=$a-$c
echo "$a - $c = $x"
fi
if [ $b == "x" ]
then
let x=$a*$c
echo "$a x $c = $x"
fi
if [ $b == "/" ]
then
let x=$a/$c
echo "$a / $c = $x"
fi
else
echo "$c is not data"
fi
else
echo "$a is not data"
fi

 

 

运行效果:

 

 进行加减乘除的shell运算脚本_职场