谁来帮我看看我这个简单的shell代码错在哪里了?

hepeng19861212 2008-04-21 02:08:12
初学linux编程。谁来帮我看看我这个shell代码错在哪里了?
#!/bin/bash
#用户输入一个分数,程序给出相应的等级
echo "input a score of student:"

read score
if [$socre -gt 100] ;then
echo "the score is invalidate!"
elif [$socre -ge 90]
echo "Excellent!"
elif [$score -ge 80]
echo "Good!"
elif [$score -ge 70]
echo "Medium!"
elif [$score -ge 60]
echo "Passed"
else
echo "Failed"
fi
exit 0
请直接给出你修改后认为正确的代码。
...全文
71 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hepeng19861212 2008-05-03
  • 打赏
  • 举报
回复
忽忽~~
2楼才是正解
错误1:见4楼
错误二:["$score" -ge 80]是错的,[ "$score" -ge 80 ] 是对的.看到他们什么区别了吧?
忽忽~~
Chdefender 2008-04-30
  • 打赏
  • 举报
回复
#!/bin/bash
#用户输入一个分数,程序给出相应的等级
echo "input a score of student:"
read score
echo
if [ "$socre" -gt 100]
then
echo "the score is invalidate!"
elif ["$socre" -ge 90]
then
echo "Excellent!"
elif ["$score" -ge 80]
then
echo "Good!"
elif [ "$score" -ge 70]
then
echo "Medium!"
elif ["$score" -ge 60]
then
echo "Passed"
else
echo "Failed"
fi
exit 0
kuyesuifeng 2008-04-30
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 explore_knight 的回复:]
echo "input a score of student:"
read score
if [ $score -gt 100 ];then
echo "the score is invalidate!"
elif [ $score -ge 90 ];then
echo "Excellent!"
elif [ $score -ge 80 ];then
echo "Good!"
elif [ $score -ge 70 ];then
echo "Medium!"
elif [ $score -ge 60 ];then
echo "Passed"
else
echo "Failed"
fi
exit 0

给我加分啊 !…
[/Quote]

正解,只要在每个elif后加上;then即可
UltraBejing 2008-04-30
  • 打赏
  • 举报
回复
有点难度哦
explore_knight 2008-04-21
  • 打赏
  • 举报
回复
echo "input a score of student:"
read score
if [ $score -gt 100 ];then
echo "the score is invalidate!"
elif [ $score -ge 90 ];then
echo "Excellent!"
elif [ $score -ge 80 ];then
echo "Good!"
elif [ $score -ge 70 ];then
echo "Medium!"
elif [ $score -ge 60 ];then
echo "Passed"
else
echo "Failed"
fi
exit 0

给我加分啊 ! 我急需。
老腊肉泡酒 2008-04-21
  • 打赏
  • 举报
回复
我都是一问就是50分第二天加分的。

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧