skip to Main Content

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)

2

Answers


  1. Put the return statement after the closing brace

    }
    return
    cat <<- _EOF_
    <html>
    
    Login or Signup to reply.
  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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search