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 !
铭哥来答疑下么?谢谢
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 !
铭哥来答疑下么?谢谢
0
有一处你写错了,不应该是 ((a=60)) 这个是赋值符号,而非等于号,应该写成 ((a==60))
在sehll中,建议写成这样的格式,更容易理解:
[ a -lt 60 ]
[ a -eq 60 ]
[ a -gt 60 ]
在sehll中,建议写成这样的格式,更容易理解:
[ a -lt 60 ]
[ a -eq 60 ]
[ a -gt 60 ]
0
铭哥,按照这样写,也是有些报错,后来发现是我没有加$ ,现在的脚本又重写了一遍,现在这里贴出来
#!/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 ! "
#!/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 ! "
编辑回复