您姓名的脚本
#!/bin/bash
echo "what is your name?"
read name
if test "$name" = "Daryl"
then
echo "Hey, how are you?"
else
echo "sorry, im looking for Daryl"
fi
yourGrade的脚本
#!/bin/bash
./yourname
if[ 0 -eq "$?" ]
then
exit 0
else
echo "what is your grade?"
read grade
if [ "$grade" -gt 90 ]
then
echo "Awesome! You got an A"
elif [ "$grade -le 90 ] && [ "$grade" -gt 80 ]
then
echo "Good! You got a B"
elif [ "$grade" -lt 80 ];
then
echo "You need to work harder!"
fi
我正在尝试获取它,以便在脚本yourGrade中使用您的名字检查它是否为Daryl,如果不停止该程序。然后,如果询问等级,则读取等级值并根据等级返回适当的消息。
每次运行它我都会得到...
root@kali:~# . yourGrade
What is your name?
>Daryl
Hey how are you!
-bash : yourGrade: line 17: syntax error near unexpected token 'elif'
-bash : yourGrade: line 17:' elif [ "$grade" -le 90 ] && [ "$grade" -gt 80 ]'
任何帮助,将不胜感激!
你有几个问题。
发生“意外的EOF”问题是因为您有不匹配的双引号:
elif [ "$grade -le 90 ] && [ "$grade" -gt 80 ]
你需要:
elif [ "$grade" -le 90 ] && [ "$grade" -gt 80 ]
解决此问题后,您将遇到以下问题:
if[ 0 -eq "$?" ]
该[
是命令,而当它本身就是一个字时,才能识别为命令。您需要在if
和之间放置一个空格[
。
if [ 0 -eq "$?" ]
然后,由于缩进不稳定,您将遇到一个问题,实际上您有两个if
语句(一个嵌套在另一个语句中),只有一个fi
;绑在你身上!
最后要注意的是,得分不超过80的人不会对他们的评分有所了解。
#!/bin/bash
./yourname
if [ 0 -eq "$?" ]
then
exit 0
else
echo "what is your grade?"
read grade
if [ "$grade" -gt 90 ]
then
echo "Awesome! You got an A"
elif [ "$grade" -le 90 ] && [ "$grade" -gt 80 ]
then
echo "Good! You got a B"
elif [ "$grade" -lt 80 ];
then
echo "You need to work harder!"
else
echo "You scored 80; that's only barely acceptable"
fi
fi
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句