请教Shell下的一个函数问题
Shell脚本如下:#!/bin/bash
count()
{
if [ $# -ne 3 ]
then
echo "The number of arguments is not 3!"
fi
let "s = 0"
case $2 in
+)
let "s = $1 + $3"
echo "$1 + $3 = $s";;
-)
let "s = $1 - $3"
echo "$1 - $3 = $s";;
\*)
let "s = $1 * $3"
echo "$1 * $3 = $s";;
\/)
let "s = $1 / $3"
echo "$1 / $3 = $s";;
*)
echo "What you input is wrong!";;
esac
}
echo "Please type you word:(e.g. 1 + 1)"
read a b c
count $a $b $c
脚本测试如下:
1.测试加法
[root@localhost 13study]# sh function5.sh
Please type you word:(e.g. 1 + 1)
3 + 3
3 + 3 = 6
2.测试减法
[root@localhost 13study]# sh function5.sh
Please type you word:(e.g. 1 + 1)
3 - 3
3 - 3 = 0
3.测试乘法
[root@localhost 13study]# sh function5.sh
Please type you word:(e.g. 1 + 1)
3 * 3
The number of arguments is not 3!
What you input is wrong!
4.测试除法
[root@localhost 13study]# sh function5.sh
Please type you word:(e.g. 1 + 1)
3 / 3
3 / 3 = 1
为什么乘法测试结果不对,问题出在哪里?是因为“*”星号符么,要如何操作才正确。请高手指点下。谢谢,谢谢