Linux – The file ended unexpectedly

The file ended unexpectedly… here is a solution to the problem.

The file ended unexpectedly

I was

asked to modify a bash script during my internship because yesterday was the first time I started reading Bash syntax, so I had a hard time figuring out the “syntax error: File ended unexpectedly” error. I was wondering if anyone could help me.

The last part of the script is:

    echo "  " >>${MAILLOG}

echo "Building CSAPI SDK" >>${MAILLOG}
        cd ${BuildsDIR}
        make sdk
    # Wait 3 minutes for the HDXs to reboot and SDK build to complete
    echo "Waiting for the HDXs to reboot and SDK build to complete..." >>${MAILLOG}
        sleep 180
    echo "Running PyUnit tests" >>${MAILLOG}
        cd Common/csapi/pyunit
        make test >>${TESTLOG} 2>&1

TestReportLink=`mklink ${BUILDURL}/${1}/build/Common/csapi/pyunit/report.xml`
    TestLogLink=`mklink ${BUILDURL}/${1}/build/${1}.test.log`

echo "Test report: ${TestReportLink}" >>${MAILLOG} 
    echo "Test log: ${TestLogLink}"  >>${MAILLOG} 
    # Wait 3 minutes for the tests to complete
        sleep 180

Solution

Appears around line 129 of the script:

    EOFBUILDFAILUREMSG

Remove the leading space from the line and your error message disappears.

This is the closing separator for the here document. If you change line 123 to set the redirect operator to <<-, you can keep leading spaces. Whitespace contains only tabs (no spaces):

    cat <<-EOFBUILDFAILUREMSG >>${MAILLOG}

Related Problems and Solutions