Ubuntu – Unexpected end of file

bash

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

Best Answer

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
Related Question