`syntax error: unexpected end of file` report after carefully being checked
Clash 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?
shell
 |Â
show 6 more comments
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?
shell
1
Are you sure that those_EOF_
where used to delimit<<- _EOF_
heredocs are preceded by one and only one TAB character? (no space?). doessed -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 been2,
instead of2,
. 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
 |Â
show 6 more comments
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?
shell
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?
shell
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?). doessed -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 been2,
instead of2,
. 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
 |Â
show 6 more comments
1
Are you sure that those_EOF_
where used to delimit<<- _EOF_
heredocs are preceded by one and only one TAB character? (no space?). doessed -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 been2,
instead of2,
. 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
 |Â
show 6 more comments
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.
ty very much. I add extension.sh
, vscode colored visually the problem.
â JawSaw
Apr 1 at 9:38
add a comment |Â
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.
ty very much. I add extension.sh
, vscode colored visually the problem.
â JawSaw
Apr 1 at 9:38
add a comment |Â
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.
ty very much. I add extension.sh
, vscode colored visually the problem.
â JawSaw
Apr 1 at 9:38
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Are you sure that those
_EOF_
where used to delimit<<- _EOF_
heredocs are preceded by one and only one TAB character? (no space?). doessed -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 of2,
. 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