`syntax error: unexpected end of file` report after carefully being checked

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I encounter syntax error: unexpected end of file during running the following program.



 #! /bin/bash
# Program to output a system information

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME="$(date +"%x %r %Z")"
TIMESTAMP="Generated $CURRENT_TIME, by $USER"

report_uptime ()
cat <<- _EOF_
<h2>System Uptime</h2>
<pre>$(uptime)</pre>
_EOF_
return


report_disk_space ()
cat <<- _EOF_
<h2>Disk Space Utilization</h2>
<pre>$(df -h)</pre>
_EOF_
return


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


cat << _EOF_
<HTML>
<HEAD>
<TITLE>$TITLE</TITLE>
</HEAD>
<BODY>
<h1>$TITLE</h1>
<p>$TIMESTAMP</p>
$(report_uptime)
$(report_disk_space)
$(report_home_space)
</BODY>
</HTML>
_EOF_


I debug it in separate units, there's no bugs from cat << _EOF to the end



 me at me in ~/desktop
$ cat << _EOF_
→ <HTML>
→ <HEAD>
→ <TITLE>$TITLE</TITLE>
→ </HEAD>
→ <BODY>
→ <h1>$TITLE</h1>
→ <p>$TIMESTAMP</p>
→ $(report_uptime)
→ $(report_disk_space)
→ $(report_home_space)
→ </BODY>
→ </HTML>
→ _EOF_
<HTML>
<HEAD>
<TITLE>System Information Report For Max-2018.local</TITLE>
</HEAD>
<BODY>
<h1>System Information Report For Max-2018.local</h1>
<p>Generated 04/01/2018 02:46:34 PM CST, by me</p>



</BODY>
</HTML>


Furthermore, there's also no bugs if I eliminate all the commands in shell functions.



What's the bug it might be?







share|improve this question
















  • 1




    Are you sure that those _EOF_ where used to delimit <<- _EOF_ heredocs are preceded by one and only one TAB character? (no space?). does sed -n '/^[[:space:]]2,_EOF_/l' return something?
    – Stéphane Chazelas
    Apr 1 at 7:25







  • 1




    Assuming all here-documents are indented by real tabs, I can see no issues with this script, apart from trying to access ~/home/* (did you mean /home/*?). If a here-document is delimited by the end of the file, you will get a warning saying "here-document at line NN delimited by end-of-file...". I'm also assuming that the extra indentation of all code is a formatting error on this site and not in your script.
    – Kusalananda
    Apr 1 at 7:36







  • 1




    Is the script a DOS text file, or does it contain carriage returns on some lines?
    – Kusalananda
    Apr 1 at 7:49






  • 1




    @Tool sorry my bad. It should have been 2, instead of 2,. More generally, sed -n l to see invisible characters.
    – Stéphane Chazelas
    Apr 1 at 7:59






  • 1




    Well, if I copy and paste the script from your question, remove the extra indentation and replace the indentation for the here-documents with tabs, it works.
    – Kusalananda
    Apr 1 at 8:29















up vote
0
down vote

favorite












I encounter syntax error: unexpected end of file during running the following program.



 #! /bin/bash
# Program to output a system information

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME="$(date +"%x %r %Z")"
TIMESTAMP="Generated $CURRENT_TIME, by $USER"

report_uptime ()
cat <<- _EOF_
<h2>System Uptime</h2>
<pre>$(uptime)</pre>
_EOF_
return


report_disk_space ()
cat <<- _EOF_
<h2>Disk Space Utilization</h2>
<pre>$(df -h)</pre>
_EOF_
return


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


cat << _EOF_
<HTML>
<HEAD>
<TITLE>$TITLE</TITLE>
</HEAD>
<BODY>
<h1>$TITLE</h1>
<p>$TIMESTAMP</p>
$(report_uptime)
$(report_disk_space)
$(report_home_space)
</BODY>
</HTML>
_EOF_


I debug it in separate units, there's no bugs from cat << _EOF to the end



 me at me in ~/desktop
$ cat << _EOF_
→ <HTML>
→ <HEAD>
→ <TITLE>$TITLE</TITLE>
→ </HEAD>
→ <BODY>
→ <h1>$TITLE</h1>
→ <p>$TIMESTAMP</p>
→ $(report_uptime)
→ $(report_disk_space)
→ $(report_home_space)
→ </BODY>
→ </HTML>
→ _EOF_
<HTML>
<HEAD>
<TITLE>System Information Report For Max-2018.local</TITLE>
</HEAD>
<BODY>
<h1>System Information Report For Max-2018.local</h1>
<p>Generated 04/01/2018 02:46:34 PM CST, by me</p>



</BODY>
</HTML>


Furthermore, there's also no bugs if I eliminate all the commands in shell functions.



What's the bug it might be?







share|improve this question
















  • 1




    Are you sure that those _EOF_ where used to delimit <<- _EOF_ heredocs are preceded by one and only one TAB character? (no space?). does sed -n '/^[[:space:]]2,_EOF_/l' return something?
    – Stéphane Chazelas
    Apr 1 at 7:25







  • 1




    Assuming all here-documents are indented by real tabs, I can see no issues with this script, apart from trying to access ~/home/* (did you mean /home/*?). If a here-document is delimited by the end of the file, you will get a warning saying "here-document at line NN delimited by end-of-file...". I'm also assuming that the extra indentation of all code is a formatting error on this site and not in your script.
    – Kusalananda
    Apr 1 at 7:36







  • 1




    Is the script a DOS text file, or does it contain carriage returns on some lines?
    – Kusalananda
    Apr 1 at 7:49






  • 1




    @Tool sorry my bad. It should have been 2, instead of 2,. More generally, sed -n l to see invisible characters.
    – Stéphane Chazelas
    Apr 1 at 7:59






  • 1




    Well, if I copy and paste the script from your question, remove the extra indentation and replace the indentation for the here-documents with tabs, it works.
    – Kusalananda
    Apr 1 at 8:29













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I encounter syntax error: unexpected end of file during running the following program.



 #! /bin/bash
# Program to output a system information

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME="$(date +"%x %r %Z")"
TIMESTAMP="Generated $CURRENT_TIME, by $USER"

report_uptime ()
cat <<- _EOF_
<h2>System Uptime</h2>
<pre>$(uptime)</pre>
_EOF_
return


report_disk_space ()
cat <<- _EOF_
<h2>Disk Space Utilization</h2>
<pre>$(df -h)</pre>
_EOF_
return


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


cat << _EOF_
<HTML>
<HEAD>
<TITLE>$TITLE</TITLE>
</HEAD>
<BODY>
<h1>$TITLE</h1>
<p>$TIMESTAMP</p>
$(report_uptime)
$(report_disk_space)
$(report_home_space)
</BODY>
</HTML>
_EOF_


I debug it in separate units, there's no bugs from cat << _EOF to the end



 me at me in ~/desktop
$ cat << _EOF_
→ <HTML>
→ <HEAD>
→ <TITLE>$TITLE</TITLE>
→ </HEAD>
→ <BODY>
→ <h1>$TITLE</h1>
→ <p>$TIMESTAMP</p>
→ $(report_uptime)
→ $(report_disk_space)
→ $(report_home_space)
→ </BODY>
→ </HTML>
→ _EOF_
<HTML>
<HEAD>
<TITLE>System Information Report For Max-2018.local</TITLE>
</HEAD>
<BODY>
<h1>System Information Report For Max-2018.local</h1>
<p>Generated 04/01/2018 02:46:34 PM CST, by me</p>



</BODY>
</HTML>


Furthermore, there's also no bugs if I eliminate all the commands in shell functions.



What's the bug it might be?







share|improve this question












I encounter syntax error: unexpected end of file during running the following program.



 #! /bin/bash
# Program to output a system information

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME="$(date +"%x %r %Z")"
TIMESTAMP="Generated $CURRENT_TIME, by $USER"

report_uptime ()
cat <<- _EOF_
<h2>System Uptime</h2>
<pre>$(uptime)</pre>
_EOF_
return


report_disk_space ()
cat <<- _EOF_
<h2>Disk Space Utilization</h2>
<pre>$(df -h)</pre>
_EOF_
return


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


cat << _EOF_
<HTML>
<HEAD>
<TITLE>$TITLE</TITLE>
</HEAD>
<BODY>
<h1>$TITLE</h1>
<p>$TIMESTAMP</p>
$(report_uptime)
$(report_disk_space)
$(report_home_space)
</BODY>
</HTML>
_EOF_


I debug it in separate units, there's no bugs from cat << _EOF to the end



 me at me in ~/desktop
$ cat << _EOF_
→ <HTML>
→ <HEAD>
→ <TITLE>$TITLE</TITLE>
→ </HEAD>
→ <BODY>
→ <h1>$TITLE</h1>
→ <p>$TIMESTAMP</p>
→ $(report_uptime)
→ $(report_disk_space)
→ $(report_home_space)
→ </BODY>
→ </HTML>
→ _EOF_
<HTML>
<HEAD>
<TITLE>System Information Report For Max-2018.local</TITLE>
</HEAD>
<BODY>
<h1>System Information Report For Max-2018.local</h1>
<p>Generated 04/01/2018 02:46:34 PM CST, by me</p>



</BODY>
</HTML>


Furthermore, there's also no bugs if I eliminate all the commands in shell functions.



What's the bug it might be?









share|improve this question











share|improve this question




share|improve this question










asked Apr 1 at 7:13









JawSaw

29410




29410







  • 1




    Are you sure that those _EOF_ where used to delimit <<- _EOF_ heredocs are preceded by one and only one TAB character? (no space?). does sed -n '/^[[:space:]]2,_EOF_/l' return something?
    – Stéphane Chazelas
    Apr 1 at 7:25







  • 1




    Assuming all here-documents are indented by real tabs, I can see no issues with this script, apart from trying to access ~/home/* (did you mean /home/*?). If a here-document is delimited by the end of the file, you will get a warning saying "here-document at line NN delimited by end-of-file...". I'm also assuming that the extra indentation of all code is a formatting error on this site and not in your script.
    – Kusalananda
    Apr 1 at 7:36







  • 1




    Is the script a DOS text file, or does it contain carriage returns on some lines?
    – Kusalananda
    Apr 1 at 7:49






  • 1




    @Tool sorry my bad. It should have been 2, instead of 2,. More generally, sed -n l to see invisible characters.
    – Stéphane Chazelas
    Apr 1 at 7:59






  • 1




    Well, if I copy and paste the script from your question, remove the extra indentation and replace the indentation for the here-documents with tabs, it works.
    – Kusalananda
    Apr 1 at 8:29













  • 1




    Are you sure that those _EOF_ where used to delimit <<- _EOF_ heredocs are preceded by one and only one TAB character? (no space?). does sed -n '/^[[:space:]]2,_EOF_/l' return something?
    – Stéphane Chazelas
    Apr 1 at 7:25







  • 1




    Assuming all here-documents are indented by real tabs, I can see no issues with this script, apart from trying to access ~/home/* (did you mean /home/*?). If a here-document is delimited by the end of the file, you will get a warning saying "here-document at line NN delimited by end-of-file...". I'm also assuming that the extra indentation of all code is a formatting error on this site and not in your script.
    – Kusalananda
    Apr 1 at 7:36







  • 1




    Is the script a DOS text file, or does it contain carriage returns on some lines?
    – Kusalananda
    Apr 1 at 7:49






  • 1




    @Tool sorry my bad. It should have been 2, instead of 2,. More generally, sed -n l to see invisible characters.
    – Stéphane Chazelas
    Apr 1 at 7:59






  • 1




    Well, if I copy and paste the script from your question, remove the extra indentation and replace the indentation for the here-documents with tabs, it works.
    – Kusalananda
    Apr 1 at 8:29








1




1




Are you sure that those _EOF_ where used to delimit <<- _EOF_ heredocs are preceded by one and only one TAB character? (no space?). does sed -n '/^[[:space:]]2,_EOF_/l' return something?
– Stéphane Chazelas
Apr 1 at 7:25





Are you sure that those _EOF_ where used to delimit <<- _EOF_ heredocs are preceded by one and only one TAB character? (no space?). does sed -n '/^[[:space:]]2,_EOF_/l' return something?
– Stéphane Chazelas
Apr 1 at 7:25





1




1




Assuming all here-documents are indented by real tabs, I can see no issues with this script, apart from trying to access ~/home/* (did you mean /home/*?). If a here-document is delimited by the end of the file, you will get a warning saying "here-document at line NN delimited by end-of-file...". I'm also assuming that the extra indentation of all code is a formatting error on this site and not in your script.
– Kusalananda
Apr 1 at 7:36





Assuming all here-documents are indented by real tabs, I can see no issues with this script, apart from trying to access ~/home/* (did you mean /home/*?). If a here-document is delimited by the end of the file, you will get a warning saying "here-document at line NN delimited by end-of-file...". I'm also assuming that the extra indentation of all code is a formatting error on this site and not in your script.
– Kusalananda
Apr 1 at 7:36





1




1




Is the script a DOS text file, or does it contain carriage returns on some lines?
– Kusalananda
Apr 1 at 7:49




Is the script a DOS text file, or does it contain carriage returns on some lines?
– Kusalananda
Apr 1 at 7:49




1




1




@Tool sorry my bad. It should have been 2, instead of 2,. More generally, sed -n l to see invisible characters.
– Stéphane Chazelas
Apr 1 at 7:59




@Tool sorry my bad. It should have been 2, instead of 2,. More generally, sed -n l to see invisible characters.
– Stéphane Chazelas
Apr 1 at 7:59




1




1




Well, if I copy and paste the script from your question, remove the extra indentation and replace the indentation for the here-documents with tabs, it works.
– Kusalananda
Apr 1 at 8:29





Well, if I copy and paste the script from your question, remove the extra indentation and replace the indentation for the here-documents with tabs, it works.
– Kusalananda
Apr 1 at 8:29











1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










When you use the <<- EOF operator, the EOF delimiter has to be preceded by TABs only (or be at the start of the line), not spaces. A line that consists of <space>EOF or <space><TAB>EOF is not seen as delimiter.



In:



... <<- EOF
<TAB>line1
<TAB>line2
<TAB>continued
<TAB>line3
<TAB>EOF


The leading TABs (above represented as <TAB>) are removed (except for the logical line2 line continued on the next physical lines, except in old versions of zsh before it was fixed) before the EOF is looked for.



So here, you'd need to remove all the space characters before the _EOF_ delimiter. Or better, avoid that <<- altogether and use put the _EOF_ at the beginning of the line (making sure it's not followed by blanks). Personally, I don't like the idea of a language where the syntax depends on the amount of spaces, that's the main thing I dislike about python as well.






share|improve this answer






















  • ty very much. I add extension .sh, vscode colored visually the problem.
    – JawSaw
    Apr 1 at 9:38










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f434795%2fsyntax-error-unexpected-end-of-file-report-after-carefully-being-checked%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










When you use the <<- EOF operator, the EOF delimiter has to be preceded by TABs only (or be at the start of the line), not spaces. A line that consists of <space>EOF or <space><TAB>EOF is not seen as delimiter.



In:



... <<- EOF
<TAB>line1
<TAB>line2
<TAB>continued
<TAB>line3
<TAB>EOF


The leading TABs (above represented as <TAB>) are removed (except for the logical line2 line continued on the next physical lines, except in old versions of zsh before it was fixed) before the EOF is looked for.



So here, you'd need to remove all the space characters before the _EOF_ delimiter. Or better, avoid that <<- altogether and use put the _EOF_ at the beginning of the line (making sure it's not followed by blanks). Personally, I don't like the idea of a language where the syntax depends on the amount of spaces, that's the main thing I dislike about python as well.






share|improve this answer






















  • ty very much. I add extension .sh, vscode colored visually the problem.
    – JawSaw
    Apr 1 at 9:38














up vote
2
down vote



accepted










When you use the <<- EOF operator, the EOF delimiter has to be preceded by TABs only (or be at the start of the line), not spaces. A line that consists of <space>EOF or <space><TAB>EOF is not seen as delimiter.



In:



... <<- EOF
<TAB>line1
<TAB>line2
<TAB>continued
<TAB>line3
<TAB>EOF


The leading TABs (above represented as <TAB>) are removed (except for the logical line2 line continued on the next physical lines, except in old versions of zsh before it was fixed) before the EOF is looked for.



So here, you'd need to remove all the space characters before the _EOF_ delimiter. Or better, avoid that <<- altogether and use put the _EOF_ at the beginning of the line (making sure it's not followed by blanks). Personally, I don't like the idea of a language where the syntax depends on the amount of spaces, that's the main thing I dislike about python as well.






share|improve this answer






















  • ty very much. I add extension .sh, vscode colored visually the problem.
    – JawSaw
    Apr 1 at 9:38












up vote
2
down vote



accepted







up vote
2
down vote



accepted






When you use the <<- EOF operator, the EOF delimiter has to be preceded by TABs only (or be at the start of the line), not spaces. A line that consists of <space>EOF or <space><TAB>EOF is not seen as delimiter.



In:



... <<- EOF
<TAB>line1
<TAB>line2
<TAB>continued
<TAB>line3
<TAB>EOF


The leading TABs (above represented as <TAB>) are removed (except for the logical line2 line continued on the next physical lines, except in old versions of zsh before it was fixed) before the EOF is looked for.



So here, you'd need to remove all the space characters before the _EOF_ delimiter. Or better, avoid that <<- altogether and use put the _EOF_ at the beginning of the line (making sure it's not followed by blanks). Personally, I don't like the idea of a language where the syntax depends on the amount of spaces, that's the main thing I dislike about python as well.






share|improve this answer














When you use the <<- EOF operator, the EOF delimiter has to be preceded by TABs only (or be at the start of the line), not spaces. A line that consists of <space>EOF or <space><TAB>EOF is not seen as delimiter.



In:



... <<- EOF
<TAB>line1
<TAB>line2
<TAB>continued
<TAB>line3
<TAB>EOF


The leading TABs (above represented as <TAB>) are removed (except for the logical line2 line continued on the next physical lines, except in old versions of zsh before it was fixed) before the EOF is looked for.



So here, you'd need to remove all the space characters before the _EOF_ delimiter. Or better, avoid that <<- altogether and use put the _EOF_ at the beginning of the line (making sure it's not followed by blanks). Personally, I don't like the idea of a language where the syntax depends on the amount of spaces, that's the main thing I dislike about python as well.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 1 at 9:12

























answered Apr 1 at 8:57









Stéphane Chazelas

280k53514846




280k53514846











  • ty very much. I add extension .sh, vscode colored visually the problem.
    – JawSaw
    Apr 1 at 9:38
















  • ty very much. I add extension .sh, vscode colored visually the problem.
    – JawSaw
    Apr 1 at 9:38















ty very much. I add extension .sh, vscode colored visually the problem.
– JawSaw
Apr 1 at 9:38




ty very much. I add extension .sh, vscode colored visually the problem.
– JawSaw
Apr 1 at 9:38












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f434795%2fsyntax-error-unexpected-end-of-file-report-after-carefully-being-checked%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay