2017-07-10 8 views
-1

Wir verwenden die Bourne-Again-Shell.Bash-Syntax Fehler Syntaxfehler: unerwartetes Ende der Datei

Was bedeuten diese Fehler ?:

syntax error: unexpected end of file

PS3="Press 1, 2, 3, 4 to do the thing they say next to them." 
options=("Option 1" "Option 2" "Option 3" "Quit") 
select opt in "${options[@]}" 
do 
    case $opt in 
     "start game") 
      echo ok 
      ;; 
     "level select") 
      echo "no" 
      ;; 
     "how do i exit") 
      echo "click the window to close" 
     xkill 
      ;; 
     "exit") 
      echo wwaaaatttt 
     echo click the window to kill it. 
      xkill 
      echo "if your reading this, you must have opened 
      echo "a game file. you've bricked the exit 
      echo button. great job. 
      ;; 
     *) echo not a thing, sorry;; 
    esac 
done 
+0

Was Sie versuchen zu tun, wenn Sie diesen Fehler erhalten? Ein Skript ausführen? Eine Datei verarbeiten? Welche Sprachen werden speziell verwendet? Gibt es weitere Details zu dem Fehler? – Theyna

+1

Hallo und willkommen bei StackOverflow. Bitte nehmen Sie sich etwas Zeit, um die Hilfeseite zu lesen, insbesondere die Abschnitte mit dem Namen ["Welche Themen kann ich hier fragen?"] (Http://stackoverflow.com/help/on-topic) und ["Welche Arten von Fragen sollte ich haben nicht fragen? "] (http://stackoverflow.com/help/dont-ask). Und, was noch wichtiger ist, lesen Sie bitte [die Checkliste für Stack Overflow-Fragen] (http://meta.stackexchange.com/q/156810/204922). Vielleicht möchten Sie auch etwas über [Minimale, vollständige und überprüfbare Beispiele] (http://stackoverflow.com/help/mcve) erfahren. – jmunsch

+0

siehe auch: https://stackoverflow.com/questions/6366530/bash-syntax-error-unexpected-end-of-file – jmunsch

Antwort

2

Die einzige Zeichenfolge in Anführungszeichen mit

ve bricked the 

Start wird das Schließen Apostroph fehlt. SO's Syntax Highlighting zeigt es auch.

Vielleicht wollten Sie Backslash das Zitat?

echo "a game file. you\'ve bricked the exit 

oder gibt es auch doppelte Anführungszeichen, die fehlen?

echo "if you're reading this, you must have opened" 
echo "a game file. you've bricked the exit" 
echo "button. great job." 

In einem solchen Fall können Sie auch eine HERE-doc verwenden:

cat << 'EOF' 
if you're reading this, you must have opened 
a game file. you've bricked the exit 
button. great job. 
EOF 
+0

DANKE SO VIEL. –

+0

"Danke" == Upvote/akzeptieren. – choroba

+0

gut, das scheint nur ein wenig Roboter –

1

ShellCheck ist hilfreich:

Line 20: 
      echo "if your reading this, you must have opened 
       ^-- SC1078: Did you forget to close this double quoted string? 

Und in der Tat haben Sie. Auch in der nächsten Zeile.

Hier ist das Skript ohne Syntaxfehler (aber Sie haben immer noch die Optionen beheben sie zuzugreifen):

PS3="Press 1, 2, 3, 4 to do the thing they say next to them." 
options=("Option 1" "Option 2" "Option 3" "Quit") 
select opt in "${options[@]}" 
do 
    case $opt in 
     "start game") 
      echo ok 
      ;; 
     "level select") 
      echo "no" 
      ;; 
     "how do i exit") 
      echo "click the window to close" 
     xkill 
      ;; 
     "exit") 
      echo wwaaaatttt 
     echo click the window to kill it. 
      xkill 
      echo "if your reading this, you must have opened" # HERE 
      echo "a game file. you've bricked the exit"  # HERE 
      echo button. great job. 
      ;; 
     *) echo not a thing, sorry;; 
    esac 
done 
+0

i shellcheck brauchen –

+0

Online ausprobieren oder es von Ihrem Linux-Paket-Manager installieren –

+0

ich weiß, wie –

Verwandte Themen