Linux 意外的EOF错误

Linux 意外的EOF错误,linux,unix,scripting,Linux,Unix,Scripting,你名字的脚本 #!/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 为你的成绩写剧本 #!/bin/bash ./yourname if[ 0 -eq "$?" ] then e

你名字的脚本

  #!/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
为你的成绩写剧本

  #!/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 [ 0 -eq "$?" ]
然后,由于缩进不稳定,您会遇到问题,事实上,您有两个
if
语句(一个嵌套在另一个中),只有一个
fi
;fie在您身上

最后要注意的是,那些分数正好为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

“谢谢你”?谢谢你的帮助,我是这方面的新手,所以这真的很有帮助!