Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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


timeend=$(date -u +%H%M)
timestart=$(date --date "$timeend 30 minutes ago" -u +%H%M)

while true
    if [[ $firsttime -eq 0 ]]; then
    if [[ $firsttime -ne true ]]; then
    increment=$(( $increment + 2 ))
    time=$(( $timestart + $increment ))
    if [[ $time -ge $timeend ]]; then

    gpnids << EOF
    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



share|improve this question
This question might be better asked on 'code review', another stack exchange site. – Charles Green Jun 19 '14 at 16:19
Thanks for the tip, I added that site to my favorites and will turn to it for future scripting issues unless they might benefit the general user. – WxPilot Jun 19 '14 at 16:25
@CharlesGreen No way. CR says clearly: "However, if your question is ... about ... Trouble-shooting, debugging, or understanding code snippets ... then your question is off-topic for this site". Btw., CR is a young beta site with hardly anyone wasting their time there. – maaartinus Jun 19 '14 at 19:38
@maaartinus Crud - I thought since it said 'peer review' that it would be filled with people trying to figure out how to write code effectively. How about 'stack overflow'? – Charles Green Jun 19 '14 at 22:00
@CharlesGreen It's just about improving code and code style, definitely not about finding bugs. SO or Linux might be a better fit, as there's nothing Ubuntu-specific in this question. IMHO it all should be a single site with content nicely separated by "site-tags" (this question should be site-tagged SO and Linux). – maaartinus Jun 19 '14 at 22:09

3 Answers 3

up vote 8 down vote accepted

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

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

/home/terdon/scripts/ 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:


cat << EOF

But this doesn't:


cat << EOF
share|improve this answer
That fixed it, I guess my assumption that whitespace is always a safe bet is wrong. Thanks! – WxPilot Jun 19 '14 at 16:26
@WxPilot very wrong. There are many cases where whitespace is a problem in bash. For example foo = bar fails, as does foo= bar, in many cases bash will automatically split on whitespace etc. You should always avoid it unless absolutely necessary. – terdon Jun 19 '14 at 16:30
I'll keep that in mind when I'm dealing with scripts – WxPilot Jun 19 '14 at 16:37

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

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

    command <<-EOF

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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