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]# 展开
#!/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]# 展开
1个回答
展开全部
将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
=============================================
以下是修改的参考意见
=============================================
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
=============================================
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询