shell编程case语句小纠错

[root@localhostshell]#catselect.case#!/bin/bash#"select""case"Usageecho"ais5,bis3.Ple... [root@localhost shell]# cat select.case
#!/bin/bash
# "select" "case" Usage
echo "a is 5,b is 3. Please select you method: "
a=5
b=3
select var in "a+b" "a-b" "a/b"
do
break
done
case $var in
"a+b") echo `a+b=` `expr $a "+" $b`;;
"a-b") echo `a-b=` `expr $a "-" $b`;;
"a*b") echo `a*b=` `expr $a "*" $b`;;
"a/b") echo `a/b=` `expr $a "/" $b`;;
*) echo "input error..."
esac
[root@localhost shell]# sh select.case
a is 5,b is 3. Please select you method:
1) a+b
2) a-b
3) a/b
#? 1
select.case: line 14: a+b=: command not found
8
[root@localhost shell]#
展开
 我来答
xmenlab
2013-04-14 · TA获得超过180个赞
知道小有建树答主
回答量:96
采纳率:0%
帮助的人:138万
展开全部
将14行~18行中echo后的a+b a-b a*b和a/b表达式的符号(`)改为单引号(')或者双引号(")即可.
以下是修改的参考意见
=============================================
a is 5,b is 3. Please select you method:
1) a+b
2) a-b
3) a/b
#? 1
a+b= 8
[ywzhou@X220i: ~/tmp]$ cat test.sh
#!/bin/bash
# "select" "case" Usage
echo "a is 5,b is 3. Please select you method: "
a=5
b=3
select var in "a+b" "a-b" "a/b"
do
break
done
case $var in
"a+b") echo 'a+b=' `expr $a "+" $b`;;
"a-b") echo 'a-b=' `expr $a "-" $b`;;
"a*b") echo 'a*b=' `expr $a "*" $b`;;
"a/b") echo 'a/b=' `expr $a "/" $b`;;
*) echo "input error..."
esac
=============================================
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式