例子,shell/ target=_blank class=infotextkey>shell脚本进行加减乘除运算。
#!/bin/bash
#
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