- 论坛徽章:
- 0
|
刚刚学shell,做练习写了下面的脚本:
#!/bin/bash
echo -e "please enter the first number:\c"
read anum
echo -e "please enter the second number:\c"
read bnum
echo -e "please select a meta between (+,-,*,/)\c"
read yourmeta
var1=`expr $anum + $bnum`
var2=`expr $anum - $bnum`
var3=`expr $anum \* $bnum`
var4=`expr $anum / $bnum`
case $yourmeta in
+) echo -e "$var1"
;;
-) echo -e "$var2"
;;
*) echo -e "$var3"
;;
/) echo -e "$var4"
;;
*) echo -e "your select is not between (+,-,*,/)"
;;
esac
计算结果如下:
marmot@sles11xen:~> sh t10.sh
please enter the first number:30
please enter the second number:15
please select a meta between (+,-,*,/)+
45
marmot@sles11xen:~> sh t10.sh
please enter the first number:30
please enter the second number:15
please select a meta between (+,-,*,/)-
15
marmot@sles11xen:~> sh t10.sh
please enter the first number:30
please enter the second number:15
please select a meta between (+,-,*,/)*
450
marmot@sles11xen:~> sh t10.sh
please enter the first number:30
please enter the second number:15
please select a meta between (+,-,*,/)/
450
marmot@sles11xen:~> sh t10.sh
please enter the first number:30
please enter the second number:15
please select a meta between (+,-,*,/)sdfsdf
450
marmot@sles11xen:~>
这究竟是怎么回子事儿啊。。。为啥只有加减乘对, 而除和其它无效字符都按乘法算。。。。。 |
|