2015-11-23 93 views
2

的腳本提供yourname意外的EOF錯誤

#!/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它需要你的姓名檢查,這是達里爾,如果不停止程序。然後如果是要求等級,則讀取等級值並根據等級返回相應的消息。

我每次運行它,我得到...

[email protected]:~# . 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 ]' 

任何幫助,將不勝感激!

+0

感謝您的幫助,我是一個新手,所以這真的有幫助! – bobblehead808

回答

4

你有幾個問題。

發生的「意外的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 
+0

「Fie on you」? ghoti