Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Unexpected end of file

Writer Mia Lopez

Can someone explain why the end of the file is unexpected on line 49? (Line 49 is one line after the last line)

#!/bin/bash
timeend=$(date -u +%H%M)
timestart=$(date --date "$timeend 30 minutes ago" -u +%H%M)
firsttime=0
while true
do if [[ $firsttime -eq 0 ]]; then time=$timestart increment=0 fi if [[ $firsttime -ne true ]]; then increment=$(( $increment + 2 )) time=$(( $timestart + $increment )) fi if [[ $time -ge $timeend ]]; then break fi gpnids << EOF RADFIL = NEXRIII|CLT|TR0 RADTIM = "$time" TITLE = 1/-2 PANEL = 0 DEVICE = gif|radar"$increment".gif|1280;1024|C CLEAR = Y TEXT = 1/2/2/hw COLORS = 7 WIND = LINE = CLRBAR = IMCBAR = 5/v/LL/.005;.6/.4;.01 GAREA = dset MAP = 24 + 23 + 1/1/2 + 14 + 15/1/2 LATLON = 0 OUTPUT = t $mapfil = lorvus.usg + hicnus.nws + hipona.nws + louhus.nws + loisus.nws run exit EOF firsttime=1 gpend done
5

4 Answers

You should also have gotten another error which is perhaps more informative:

/home/terdon/scripts/b.sh: line 49: warning: here-document at line 21 delimited by end-of-file (wanted `EOF')

/home/terdon/scripts/b.sh: line 50: syntax error: unexpected end of file

Your error is that you have spaces before the string that ends the heredoc. To take a simple example, this complains:

#!/bin/bash
cat << EOF hello EOF

But this doesn't:

#!/bin/bash
cat << EOF hello
EOF
3

I get two lines that should help you work out what's going on:

./test: line 48: warning: here-document at line 21 delimited by end-of-file (wanted `EOF')
./test: line 49: syntax error: unexpected end of file

Your heredoc (<< EOF) construction is incorrectly formed. It's whitespace sensitive so you either strip it back:

... command <<EOF ...
EOF

Or let it know you're tabbing it(and it must be a tab):

... command <<-EOF ... EOF

I prefer the second because it lets you structure the script a lot better... Something your script could already benefit from.

1

End of File warning

%>: line 49: warning: here-document at line 21 delimited by end-of-file (wanted 'EOF')

  • heredoc is looking for the delimiter (end tag), in this case EOF
  • it's never never recognized in your example because it is prefixed by spaces
  • the end of the actual file is reached without ever finding the delimiter; hence the warning

This can be addressed by removing the spaces, or as Terndon points out using tabs -- I didn't know this


Other

Another common error for end of file error that occurs deals with whitespace issues. Generally from copying code online formatted for Windows and running it in Linux.

This can be addressed by running dos2unix on the file to quickly convert those characters.

If you are using vim or vi try to use the command

:set list

You will be able to see spaces between the symbol $

Sometimes It's come in handy to figure out some unexpected behavior.
In this case delete the white spaces finished the job.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy