I am trying to create an spritz app. Everything was working fine, but since yesterday I keep getting this error:

./spritz: line 176: syntax error: unexpected end of file

I have checked the script file and everything seems perfect. I am confused, I have an if statement at last and it looks correct! Here is the last portion:

#checks if speed is 150
157 if [[ $2 -eq 150 ]];
158 then
159 starttime=$SECONDS
160      FS=$'\n'
161      for j in `grep --color=always -iP '\b[^aeiou\s]*[aeiou][^aeiou\s]*\K[aeiou]' $1`;
162      do
163            #Reads the text file in the centre of the screen
164            echo "                                                    ___________________"
165            echo "                                                             $j";
166            echo "                                                    ___________________"
167            echo "                                                                               Speed 150 wpm"
168            sleep  0.9;
169            clear;
170       done
171 endtime=$(($SECONDS - $starttime))
172            echo "You read $words_read words in $endtime seconds!"
173       exit 8
174 fi

What could cause that error?

closed as unclear what you're asking by mdpc, jasonwryan, Networker, Michael Homer, Archemar Mar 29 '15 at 8:23

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • (0) It might have been more useful to show us a diff from the last version that worked. … … … … … … … … Some observations (that probably don’t relate to your current, specific problem): (1) I don’t know of any circumstance where you need an unescaped ; (semicolon) at the end of a line.  You can delete the semicolons at the ends of lines 157, 161, 165, 168, and 169.  (Or you can leave them in; I guess it’s a question of style.)  … (Cont’d) – Scott Mar 29 '15 at 7:46
  • 1
    (Cont’d) …  (2) You should always quote shell variables unless you have a good reason not to and you’re sure you know what you’re doing; e.g., "$1", "$2", "$SECONDS", and "$starttime".  (3) It’s easier to read and debug code that’s indented properly.  (4) Why are you setting FS and then not using it?  (5) `…` can be written $(…).  (6) $(($SECONDS - $starttime)) can equivalently be written $((SECONDS - starttime)).  Again, this is basically an issue of style.  (7) Why are you printing "$words_read" in the loop when you aren’t modifying it in the loop? – Scott Mar 29 '15 at 7:48
  • Here’s a debugging approach: Try deleting lines 157-174 and running the script again.   If you still get the error (probably reported as being at line 157 or 158), then you know the problem isn’t in lines 157-174, and you have to look further back (so, repeat the process until the error goes away).  … (Cont’d) – Scott Mar 29 '15 at 7:49
  • (Cont’d) …  Once the error goes away, put the last lines you deleted back in, and start whittling away at them.   For example, if deleting lines 157-174 does make the error go away, put them back in, but then delete lines 159-160, 163-168, and 171-172.   Try replacing the `grep …` with a list of values.   In other words, use the process of elimination. – Scott Mar 29 '15 at 7:50
  • Remarks on a few of Scott's comments: (ad 2) if you are sure what you are doing then (in the posted code) only "$1" needs quoting, (ad 4) probably he meant IFS (and not FS)? – Janis Mar 30 '15 at 0:05

The diagnostic "unexpected end of file" is a hint that you have some unmatched or unterminated opening syntactical construct (if w/o fi, do w/o done, opening brackets w/o the associated closing one, opening but unterminated quotes, etc.). The line number pointing to the end of the script is not helpful in this case, beyond saying to inspect your syntactical constructs; the error may be anywhere in your code. You have to check that.

  • Thanks for the reply. I have found the error and fixed it! – Scott Pearce Mar 29 '15 at 22:09
  • --the error may be anywhere in your code. Created account just to upvote for this advice. – user340352 Mar 6 at 12:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.