Syntax error: end of file unexpected (expecting "}")

Syntax error: end of file unexpected (expecting "}")

Problem Description:

I am running the following script within a longer html file

report_home_space () {
 cat <<- _EOF_
 <h2>Home Space Utilization</h2>
 <pre>$(du -sh /home/*)</pre>
 _EOF_
 return
}
cat <<- _EOF_
<html>
*
  other html here
*
</html>
_EOF_

Why I am getting end of file unexpected what should I be supposed to do here ?
I have also tried cat << EOF but it does not work within my functions, the problem arises only when I insert Here Document inside a function. (I am currently using the bash shell)

Solution – 1

Put the return statement after the closing brace

}
return
cat <<- _EOF_
<html>

Solution – 2

If you are going to indent the here-doc delimiter, it must be with tab characters. In your code, everything until the last line of the script is part of the first here-doc.

report_home_space () {
  cat <<- _EOF_
        <h2>Home Space Utilization</h2>
        <pre>$(du -sh /home/*)</pre>
        _EOF_
  return
}

Here, the 8 spaces used to indent the two lines of the here document and the terminator should be replaced with a literal tab character.

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject