脚本执行问题

回复 收藏
read -p "Please enter your score : " a
if ((a<60)) || ((a<0));then
    echo "Sorry,you lost the exam..."
elif ((a=60));then
    echo "You are lucky man !"
else
    echo "Congratulations! You pass the exam !"
fi


这个脚本是仿制铭哥的脚本,可是无论你输入60,还是大于60的数字,都是打印 You are lucky man !

铭哥来答疑下么?谢谢
2013-07-01 17:27 举报
已邀请:
0

阿铭 管理员

赞同来自:

有一处你写错了,不应该是  ((a=60)) 这个是赋值符号,而非等于号,应该写成 ((a==60))

在sehll中,建议写成这样的格式,更容易理解:

[ a -lt 60 ]  
[ a -eq 60 ]
[ a -gt 60 ]
0

wikilike7

赞同来自:

谢谢铭哥,现在在一家外企,但是技术性的东西不多,很很困惑
0

wikilike7

赞同来自:

铭哥,按照这样写,也是有些报错,后来发现是我没有加$ ,现在的脚本又重写了一遍,现在这里贴出来

#!/bin/bash
#This script use to test if command
#write by wikilike7, date: 07/01/2013

read -p "Please enter you score : "  a
if  [ $a -lt 60 ];    then
echo "Sorry , you lost the exam"
elif  [ $a -eq 60 ];  then
echo "You are lucky man !"
else
echo "Congratulations ! "

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: