Why is bash checking the syntax of my here document text?
I have the following block of code in my file:
175 MY_IP=`ifconfig eno1 | grep netmask | tr -s ' ' | cut -d " " -f 3`
176 echo "" > /home/hadoop/.ssh/config
177 cat > /home/hadoop/.ssh/config <<EOF
178 Host `echo $MY_IP | sed 's/.[0-9][0-9]*$//g'`.* 0.0.0.0 master worker*
179 StrictHostKeyChecking no
180 UserKnownHostsFile=/dev/null
181 EOF
I expect lines 178 to 181 to just be written to a file, but I get this error output:
/script.sh: line 178: unexpected EOF while looking for matching `''
/script.sh: line 184: syntax error: unexpected end of file
Why is it not just copying that text instead of checking its syntax?
Update: The way my code and error messages look right now:
175 MY_IP=`ifconfig eno1 | grep netmask | tr -s ' ' | cut -d " " -f 3`
176 echo "" > /home/hadoop/.ssh/config
177 cat > /home/hadoop/.ssh/config <<EOF
178 Host `echo $MY_IP | sed "s/.[0-9][0-9]*$//g"`.* 0.0.0.0 master worker*
179 StrictHostKeyChecking no
180 UserKnownHostsFile=/dev/null
181 EOF
182
183 chown -R hadoop:hadoop /home/hadoop
/script.sh: line 175: unexpected EOF while looking for matching `''
/script.sh: line 184: syntax error: unexpected end of file
linux bash
New contributor
add a comment |
I have the following block of code in my file:
175 MY_IP=`ifconfig eno1 | grep netmask | tr -s ' ' | cut -d " " -f 3`
176 echo "" > /home/hadoop/.ssh/config
177 cat > /home/hadoop/.ssh/config <<EOF
178 Host `echo $MY_IP | sed 's/.[0-9][0-9]*$//g'`.* 0.0.0.0 master worker*
179 StrictHostKeyChecking no
180 UserKnownHostsFile=/dev/null
181 EOF
I expect lines 178 to 181 to just be written to a file, but I get this error output:
/script.sh: line 178: unexpected EOF while looking for matching `''
/script.sh: line 184: syntax error: unexpected end of file
Why is it not just copying that text instead of checking its syntax?
Update: The way my code and error messages look right now:
175 MY_IP=`ifconfig eno1 | grep netmask | tr -s ' ' | cut -d " " -f 3`
176 echo "" > /home/hadoop/.ssh/config
177 cat > /home/hadoop/.ssh/config <<EOF
178 Host `echo $MY_IP | sed "s/.[0-9][0-9]*$//g"`.* 0.0.0.0 master worker*
179 StrictHostKeyChecking no
180 UserKnownHostsFile=/dev/null
181 EOF
182
183 chown -R hadoop:hadoop /home/hadoop
/script.sh: line 175: unexpected EOF while looking for matching `''
/script.sh: line 184: syntax error: unexpected end of file
linux bash
New contributor
1
the code you posted does not generate those error messages; they're only generated if you leave out one of the single quotes from the sed command ('s/..//g'
)
– mosvy
4 hours ago
I don't expect the error either but I am getting it 100% :) Using the code just like it is in my 2nd example above.
– Steve
3 hours ago
Steve I still cannot reproduce your error message. Unless @mosvy can spot the issue, would it be possible for you to post to actual script that you are running online (at pastebin.com or similar)? There may be some issue with encoding or the prior lines that we can't see here.
– John1024
3 hours ago
1
the only possibility left is that there's an unclosed quote somewhere before line 175, as explained in @ilkkachu's answer.
– mosvy
3 hours ago
add a comment |
I have the following block of code in my file:
175 MY_IP=`ifconfig eno1 | grep netmask | tr -s ' ' | cut -d " " -f 3`
176 echo "" > /home/hadoop/.ssh/config
177 cat > /home/hadoop/.ssh/config <<EOF
178 Host `echo $MY_IP | sed 's/.[0-9][0-9]*$//g'`.* 0.0.0.0 master worker*
179 StrictHostKeyChecking no
180 UserKnownHostsFile=/dev/null
181 EOF
I expect lines 178 to 181 to just be written to a file, but I get this error output:
/script.sh: line 178: unexpected EOF while looking for matching `''
/script.sh: line 184: syntax error: unexpected end of file
Why is it not just copying that text instead of checking its syntax?
Update: The way my code and error messages look right now:
175 MY_IP=`ifconfig eno1 | grep netmask | tr -s ' ' | cut -d " " -f 3`
176 echo "" > /home/hadoop/.ssh/config
177 cat > /home/hadoop/.ssh/config <<EOF
178 Host `echo $MY_IP | sed "s/.[0-9][0-9]*$//g"`.* 0.0.0.0 master worker*
179 StrictHostKeyChecking no
180 UserKnownHostsFile=/dev/null
181 EOF
182
183 chown -R hadoop:hadoop /home/hadoop
/script.sh: line 175: unexpected EOF while looking for matching `''
/script.sh: line 184: syntax error: unexpected end of file
linux bash
New contributor
I have the following block of code in my file:
175 MY_IP=`ifconfig eno1 | grep netmask | tr -s ' ' | cut -d " " -f 3`
176 echo "" > /home/hadoop/.ssh/config
177 cat > /home/hadoop/.ssh/config <<EOF
178 Host `echo $MY_IP | sed 's/.[0-9][0-9]*$//g'`.* 0.0.0.0 master worker*
179 StrictHostKeyChecking no
180 UserKnownHostsFile=/dev/null
181 EOF
I expect lines 178 to 181 to just be written to a file, but I get this error output:
/script.sh: line 178: unexpected EOF while looking for matching `''
/script.sh: line 184: syntax error: unexpected end of file
Why is it not just copying that text instead of checking its syntax?
Update: The way my code and error messages look right now:
175 MY_IP=`ifconfig eno1 | grep netmask | tr -s ' ' | cut -d " " -f 3`
176 echo "" > /home/hadoop/.ssh/config
177 cat > /home/hadoop/.ssh/config <<EOF
178 Host `echo $MY_IP | sed "s/.[0-9][0-9]*$//g"`.* 0.0.0.0 master worker*
179 StrictHostKeyChecking no
180 UserKnownHostsFile=/dev/null
181 EOF
182
183 chown -R hadoop:hadoop /home/hadoop
/script.sh: line 175: unexpected EOF while looking for matching `''
/script.sh: line 184: syntax error: unexpected end of file
linux bash
linux bash
New contributor
New contributor
edited 3 hours ago
Steve
New contributor
asked 4 hours ago
SteveSteve
11
11
New contributor
New contributor
1
the code you posted does not generate those error messages; they're only generated if you leave out one of the single quotes from the sed command ('s/..//g'
)
– mosvy
4 hours ago
I don't expect the error either but I am getting it 100% :) Using the code just like it is in my 2nd example above.
– Steve
3 hours ago
Steve I still cannot reproduce your error message. Unless @mosvy can spot the issue, would it be possible for you to post to actual script that you are running online (at pastebin.com or similar)? There may be some issue with encoding or the prior lines that we can't see here.
– John1024
3 hours ago
1
the only possibility left is that there's an unclosed quote somewhere before line 175, as explained in @ilkkachu's answer.
– mosvy
3 hours ago
add a comment |
1
the code you posted does not generate those error messages; they're only generated if you leave out one of the single quotes from the sed command ('s/..//g'
)
– mosvy
4 hours ago
I don't expect the error either but I am getting it 100% :) Using the code just like it is in my 2nd example above.
– Steve
3 hours ago
Steve I still cannot reproduce your error message. Unless @mosvy can spot the issue, would it be possible for you to post to actual script that you are running online (at pastebin.com or similar)? There may be some issue with encoding or the prior lines that we can't see here.
– John1024
3 hours ago
1
the only possibility left is that there's an unclosed quote somewhere before line 175, as explained in @ilkkachu's answer.
– mosvy
3 hours ago
1
1
the code you posted does not generate those error messages; they're only generated if you leave out one of the single quotes from the sed command (
's/..//g'
)– mosvy
4 hours ago
the code you posted does not generate those error messages; they're only generated if you leave out one of the single quotes from the sed command (
's/..//g'
)– mosvy
4 hours ago
I don't expect the error either but I am getting it 100% :) Using the code just like it is in my 2nd example above.
– Steve
3 hours ago
I don't expect the error either but I am getting it 100% :) Using the code just like it is in my 2nd example above.
– Steve
3 hours ago
Steve I still cannot reproduce your error message. Unless @mosvy can spot the issue, would it be possible for you to post to actual script that you are running online (at pastebin.com or similar)? There may be some issue with encoding or the prior lines that we can't see here.
– John1024
3 hours ago
Steve I still cannot reproduce your error message. Unless @mosvy can spot the issue, would it be possible for you to post to actual script that you are running online (at pastebin.com or similar)? There may be some issue with encoding or the prior lines that we can't see here.
– John1024
3 hours ago
1
1
the only possibility left is that there's an unclosed quote somewhere before line 175, as explained in @ilkkachu's answer.
– mosvy
3 hours ago
the only possibility left is that there's an unclosed quote somewhere before line 175, as explained in @ilkkachu's answer.
– mosvy
3 hours ago
add a comment |
3 Answers
3
active
oldest
votes
The shell will perform different kind of expansions (including command substitutions like your `echo ...`
, but also variable and arithmetic expansions) inside here documents unless the delimiter is quoted.
Compare:
cat <<EOF
$$ $((2 + 3)) $(hostname) `date`
EOF
4502 5 fazq Mon Mar 11 23:03:27 EET 2019
vs:
cat <<'EOF'
$$ $((2 + 3)) $(hostname) `date`
EOF
$$ $((2 + 3)) $(hostname) `date`
Both double or single quotes will do in the last case.
I tried the quotes but unfortunately my error is still the same.
– Steve
4 hours ago
1
please edit your question with the exact code and error message; as it stands, the code and error message do not match.
– mosvy
4 hours ago
Thank you, I've edited the question.
– Steve
3 hours ago
add a comment |
From man bash
:
Here Documents
This type of redirection instructs the shell
to read input from the current source until a line containing only
delimiter (with no trailing blanks) is seen. All of the lines read
up to that point are then used as the standard input (or file
descriptor n if n is specified) for a command.
Your EOF line, as currently posted in the question, contains trailing blanks. Remove them.
in that case,bash
will keep reading until the end of file and only generate a warning, with a different message "here-document at line N delimited by end-of-file".
– mosvy
4 hours ago
@mosvy If I use the OP's code as posted (but minus the line numbers), I getwarning: here-document at line 3 delimited by end-of-file (wanted `EOF')
. If I remove the trailing blanks,bash -n script.sh
generates no warnings. Do you see something different? (Yes, I know that the quoted message is inconsistent with that but this wouldn't be the first time on SE that the quoted code and error message are inconsistent.)
– John1024
4 hours ago
No, they have just corrected the code before posting it ;-)
– mosvy
4 hours ago
Thank you for your response, unfortunately my file does not actually contain the trailing spaces after EOF.
– Steve
4 hours ago
@Steve After I replaceEOF
(with, as posted, the two trailing spaces) withEOF
(no trailing space) in the posted code, it generates no errors or warnings. If you are still getting an error, please document it carefully and add an update to the question.
– John1024
4 hours ago
|
show 1 more comment
We don't have the whole script here, but note how the line number on the "unexpected EOF while looking for matching [single quote]" changes from 178 to 175 when you change the quotes inside the here-doc from single quotes to double quotes.
That hints to me that the actual issue, the unfinished quote, is somewhere before the snippet you posted.
For example, in the script below the actual error is obviously on the first line, but from the shell's point of view, the quoted string started there continues until the next quote, and so on, with the unpaired one being the one after bar
(note how the syntax highlighting makes it evident that the second echo
is quoted and foo
and bar
aren't):
$ cat quote.sh
echo 'error here
echo 'foo' 'bar'
$ bash quote.sh
quote.sh: line 3: unexpected EOF while looking for matching `''
quote.sh: line 4: syntax error: unexpected end of file
Changing the second echo
command to echo "foo" "bar"
would show the error on line 1, as that would then be the line where the final single-quoted string starts.
You'll need to look through your whole script more closely. Or just dump it to shellcheck.net, it will notice cases like this.
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Steve is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505718%2fwhy-is-bash-checking-the-syntax-of-my-here-document-text%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The shell will perform different kind of expansions (including command substitutions like your `echo ...`
, but also variable and arithmetic expansions) inside here documents unless the delimiter is quoted.
Compare:
cat <<EOF
$$ $((2 + 3)) $(hostname) `date`
EOF
4502 5 fazq Mon Mar 11 23:03:27 EET 2019
vs:
cat <<'EOF'
$$ $((2 + 3)) $(hostname) `date`
EOF
$$ $((2 + 3)) $(hostname) `date`
Both double or single quotes will do in the last case.
I tried the quotes but unfortunately my error is still the same.
– Steve
4 hours ago
1
please edit your question with the exact code and error message; as it stands, the code and error message do not match.
– mosvy
4 hours ago
Thank you, I've edited the question.
– Steve
3 hours ago
add a comment |
The shell will perform different kind of expansions (including command substitutions like your `echo ...`
, but also variable and arithmetic expansions) inside here documents unless the delimiter is quoted.
Compare:
cat <<EOF
$$ $((2 + 3)) $(hostname) `date`
EOF
4502 5 fazq Mon Mar 11 23:03:27 EET 2019
vs:
cat <<'EOF'
$$ $((2 + 3)) $(hostname) `date`
EOF
$$ $((2 + 3)) $(hostname) `date`
Both double or single quotes will do in the last case.
I tried the quotes but unfortunately my error is still the same.
– Steve
4 hours ago
1
please edit your question with the exact code and error message; as it stands, the code and error message do not match.
– mosvy
4 hours ago
Thank you, I've edited the question.
– Steve
3 hours ago
add a comment |
The shell will perform different kind of expansions (including command substitutions like your `echo ...`
, but also variable and arithmetic expansions) inside here documents unless the delimiter is quoted.
Compare:
cat <<EOF
$$ $((2 + 3)) $(hostname) `date`
EOF
4502 5 fazq Mon Mar 11 23:03:27 EET 2019
vs:
cat <<'EOF'
$$ $((2 + 3)) $(hostname) `date`
EOF
$$ $((2 + 3)) $(hostname) `date`
Both double or single quotes will do in the last case.
The shell will perform different kind of expansions (including command substitutions like your `echo ...`
, but also variable and arithmetic expansions) inside here documents unless the delimiter is quoted.
Compare:
cat <<EOF
$$ $((2 + 3)) $(hostname) `date`
EOF
4502 5 fazq Mon Mar 11 23:03:27 EET 2019
vs:
cat <<'EOF'
$$ $((2 + 3)) $(hostname) `date`
EOF
$$ $((2 + 3)) $(hostname) `date`
Both double or single quotes will do in the last case.
edited 4 hours ago
answered 4 hours ago
mosvymosvy
8,1621532
8,1621532
I tried the quotes but unfortunately my error is still the same.
– Steve
4 hours ago
1
please edit your question with the exact code and error message; as it stands, the code and error message do not match.
– mosvy
4 hours ago
Thank you, I've edited the question.
– Steve
3 hours ago
add a comment |
I tried the quotes but unfortunately my error is still the same.
– Steve
4 hours ago
1
please edit your question with the exact code and error message; as it stands, the code and error message do not match.
– mosvy
4 hours ago
Thank you, I've edited the question.
– Steve
3 hours ago
I tried the quotes but unfortunately my error is still the same.
– Steve
4 hours ago
I tried the quotes but unfortunately my error is still the same.
– Steve
4 hours ago
1
1
please edit your question with the exact code and error message; as it stands, the code and error message do not match.
– mosvy
4 hours ago
please edit your question with the exact code and error message; as it stands, the code and error message do not match.
– mosvy
4 hours ago
Thank you, I've edited the question.
– Steve
3 hours ago
Thank you, I've edited the question.
– Steve
3 hours ago
add a comment |
From man bash
:
Here Documents
This type of redirection instructs the shell
to read input from the current source until a line containing only
delimiter (with no trailing blanks) is seen. All of the lines read
up to that point are then used as the standard input (or file
descriptor n if n is specified) for a command.
Your EOF line, as currently posted in the question, contains trailing blanks. Remove them.
in that case,bash
will keep reading until the end of file and only generate a warning, with a different message "here-document at line N delimited by end-of-file".
– mosvy
4 hours ago
@mosvy If I use the OP's code as posted (but minus the line numbers), I getwarning: here-document at line 3 delimited by end-of-file (wanted `EOF')
. If I remove the trailing blanks,bash -n script.sh
generates no warnings. Do you see something different? (Yes, I know that the quoted message is inconsistent with that but this wouldn't be the first time on SE that the quoted code and error message are inconsistent.)
– John1024
4 hours ago
No, they have just corrected the code before posting it ;-)
– mosvy
4 hours ago
Thank you for your response, unfortunately my file does not actually contain the trailing spaces after EOF.
– Steve
4 hours ago
@Steve After I replaceEOF
(with, as posted, the two trailing spaces) withEOF
(no trailing space) in the posted code, it generates no errors or warnings. If you are still getting an error, please document it carefully and add an update to the question.
– John1024
4 hours ago
|
show 1 more comment
From man bash
:
Here Documents
This type of redirection instructs the shell
to read input from the current source until a line containing only
delimiter (with no trailing blanks) is seen. All of the lines read
up to that point are then used as the standard input (or file
descriptor n if n is specified) for a command.
Your EOF line, as currently posted in the question, contains trailing blanks. Remove them.
in that case,bash
will keep reading until the end of file and only generate a warning, with a different message "here-document at line N delimited by end-of-file".
– mosvy
4 hours ago
@mosvy If I use the OP's code as posted (but minus the line numbers), I getwarning: here-document at line 3 delimited by end-of-file (wanted `EOF')
. If I remove the trailing blanks,bash -n script.sh
generates no warnings. Do you see something different? (Yes, I know that the quoted message is inconsistent with that but this wouldn't be the first time on SE that the quoted code and error message are inconsistent.)
– John1024
4 hours ago
No, they have just corrected the code before posting it ;-)
– mosvy
4 hours ago
Thank you for your response, unfortunately my file does not actually contain the trailing spaces after EOF.
– Steve
4 hours ago
@Steve After I replaceEOF
(with, as posted, the two trailing spaces) withEOF
(no trailing space) in the posted code, it generates no errors or warnings. If you are still getting an error, please document it carefully and add an update to the question.
– John1024
4 hours ago
|
show 1 more comment
From man bash
:
Here Documents
This type of redirection instructs the shell
to read input from the current source until a line containing only
delimiter (with no trailing blanks) is seen. All of the lines read
up to that point are then used as the standard input (or file
descriptor n if n is specified) for a command.
Your EOF line, as currently posted in the question, contains trailing blanks. Remove them.
From man bash
:
Here Documents
This type of redirection instructs the shell
to read input from the current source until a line containing only
delimiter (with no trailing blanks) is seen. All of the lines read
up to that point are then used as the standard input (or file
descriptor n if n is specified) for a command.
Your EOF line, as currently posted in the question, contains trailing blanks. Remove them.
answered 4 hours ago
John1024John1024
47.5k5110126
47.5k5110126
in that case,bash
will keep reading until the end of file and only generate a warning, with a different message "here-document at line N delimited by end-of-file".
– mosvy
4 hours ago
@mosvy If I use the OP's code as posted (but minus the line numbers), I getwarning: here-document at line 3 delimited by end-of-file (wanted `EOF')
. If I remove the trailing blanks,bash -n script.sh
generates no warnings. Do you see something different? (Yes, I know that the quoted message is inconsistent with that but this wouldn't be the first time on SE that the quoted code and error message are inconsistent.)
– John1024
4 hours ago
No, they have just corrected the code before posting it ;-)
– mosvy
4 hours ago
Thank you for your response, unfortunately my file does not actually contain the trailing spaces after EOF.
– Steve
4 hours ago
@Steve After I replaceEOF
(with, as posted, the two trailing spaces) withEOF
(no trailing space) in the posted code, it generates no errors or warnings. If you are still getting an error, please document it carefully and add an update to the question.
– John1024
4 hours ago
|
show 1 more comment
in that case,bash
will keep reading until the end of file and only generate a warning, with a different message "here-document at line N delimited by end-of-file".
– mosvy
4 hours ago
@mosvy If I use the OP's code as posted (but minus the line numbers), I getwarning: here-document at line 3 delimited by end-of-file (wanted `EOF')
. If I remove the trailing blanks,bash -n script.sh
generates no warnings. Do you see something different? (Yes, I know that the quoted message is inconsistent with that but this wouldn't be the first time on SE that the quoted code and error message are inconsistent.)
– John1024
4 hours ago
No, they have just corrected the code before posting it ;-)
– mosvy
4 hours ago
Thank you for your response, unfortunately my file does not actually contain the trailing spaces after EOF.
– Steve
4 hours ago
@Steve After I replaceEOF
(with, as posted, the two trailing spaces) withEOF
(no trailing space) in the posted code, it generates no errors or warnings. If you are still getting an error, please document it carefully and add an update to the question.
– John1024
4 hours ago
in that case,
bash
will keep reading until the end of file and only generate a warning, with a different message "here-document at line N delimited by end-of-file".– mosvy
4 hours ago
in that case,
bash
will keep reading until the end of file and only generate a warning, with a different message "here-document at line N delimited by end-of-file".– mosvy
4 hours ago
@mosvy If I use the OP's code as posted (but minus the line numbers), I get
warning: here-document at line 3 delimited by end-of-file (wanted `EOF')
. If I remove the trailing blanks, bash -n script.sh
generates no warnings. Do you see something different? (Yes, I know that the quoted message is inconsistent with that but this wouldn't be the first time on SE that the quoted code and error message are inconsistent.)– John1024
4 hours ago
@mosvy If I use the OP's code as posted (but minus the line numbers), I get
warning: here-document at line 3 delimited by end-of-file (wanted `EOF')
. If I remove the trailing blanks, bash -n script.sh
generates no warnings. Do you see something different? (Yes, I know that the quoted message is inconsistent with that but this wouldn't be the first time on SE that the quoted code and error message are inconsistent.)– John1024
4 hours ago
No, they have just corrected the code before posting it ;-)
– mosvy
4 hours ago
No, they have just corrected the code before posting it ;-)
– mosvy
4 hours ago
Thank you for your response, unfortunately my file does not actually contain the trailing spaces after EOF.
– Steve
4 hours ago
Thank you for your response, unfortunately my file does not actually contain the trailing spaces after EOF.
– Steve
4 hours ago
@Steve After I replace
EOF
(with, as posted, the two trailing spaces) with EOF
(no trailing space) in the posted code, it generates no errors or warnings. If you are still getting an error, please document it carefully and add an update to the question.– John1024
4 hours ago
@Steve After I replace
EOF
(with, as posted, the two trailing spaces) with EOF
(no trailing space) in the posted code, it generates no errors or warnings. If you are still getting an error, please document it carefully and add an update to the question.– John1024
4 hours ago
|
show 1 more comment
We don't have the whole script here, but note how the line number on the "unexpected EOF while looking for matching [single quote]" changes from 178 to 175 when you change the quotes inside the here-doc from single quotes to double quotes.
That hints to me that the actual issue, the unfinished quote, is somewhere before the snippet you posted.
For example, in the script below the actual error is obviously on the first line, but from the shell's point of view, the quoted string started there continues until the next quote, and so on, with the unpaired one being the one after bar
(note how the syntax highlighting makes it evident that the second echo
is quoted and foo
and bar
aren't):
$ cat quote.sh
echo 'error here
echo 'foo' 'bar'
$ bash quote.sh
quote.sh: line 3: unexpected EOF while looking for matching `''
quote.sh: line 4: syntax error: unexpected end of file
Changing the second echo
command to echo "foo" "bar"
would show the error on line 1, as that would then be the line where the final single-quoted string starts.
You'll need to look through your whole script more closely. Or just dump it to shellcheck.net, it will notice cases like this.
add a comment |
We don't have the whole script here, but note how the line number on the "unexpected EOF while looking for matching [single quote]" changes from 178 to 175 when you change the quotes inside the here-doc from single quotes to double quotes.
That hints to me that the actual issue, the unfinished quote, is somewhere before the snippet you posted.
For example, in the script below the actual error is obviously on the first line, but from the shell's point of view, the quoted string started there continues until the next quote, and so on, with the unpaired one being the one after bar
(note how the syntax highlighting makes it evident that the second echo
is quoted and foo
and bar
aren't):
$ cat quote.sh
echo 'error here
echo 'foo' 'bar'
$ bash quote.sh
quote.sh: line 3: unexpected EOF while looking for matching `''
quote.sh: line 4: syntax error: unexpected end of file
Changing the second echo
command to echo "foo" "bar"
would show the error on line 1, as that would then be the line where the final single-quoted string starts.
You'll need to look through your whole script more closely. Or just dump it to shellcheck.net, it will notice cases like this.
add a comment |
We don't have the whole script here, but note how the line number on the "unexpected EOF while looking for matching [single quote]" changes from 178 to 175 when you change the quotes inside the here-doc from single quotes to double quotes.
That hints to me that the actual issue, the unfinished quote, is somewhere before the snippet you posted.
For example, in the script below the actual error is obviously on the first line, but from the shell's point of view, the quoted string started there continues until the next quote, and so on, with the unpaired one being the one after bar
(note how the syntax highlighting makes it evident that the second echo
is quoted and foo
and bar
aren't):
$ cat quote.sh
echo 'error here
echo 'foo' 'bar'
$ bash quote.sh
quote.sh: line 3: unexpected EOF while looking for matching `''
quote.sh: line 4: syntax error: unexpected end of file
Changing the second echo
command to echo "foo" "bar"
would show the error on line 1, as that would then be the line where the final single-quoted string starts.
You'll need to look through your whole script more closely. Or just dump it to shellcheck.net, it will notice cases like this.
We don't have the whole script here, but note how the line number on the "unexpected EOF while looking for matching [single quote]" changes from 178 to 175 when you change the quotes inside the here-doc from single quotes to double quotes.
That hints to me that the actual issue, the unfinished quote, is somewhere before the snippet you posted.
For example, in the script below the actual error is obviously on the first line, but from the shell's point of view, the quoted string started there continues until the next quote, and so on, with the unpaired one being the one after bar
(note how the syntax highlighting makes it evident that the second echo
is quoted and foo
and bar
aren't):
$ cat quote.sh
echo 'error here
echo 'foo' 'bar'
$ bash quote.sh
quote.sh: line 3: unexpected EOF while looking for matching `''
quote.sh: line 4: syntax error: unexpected end of file
Changing the second echo
command to echo "foo" "bar"
would show the error on line 1, as that would then be the line where the final single-quoted string starts.
You'll need to look through your whole script more closely. Or just dump it to shellcheck.net, it will notice cases like this.
edited 3 hours ago
answered 3 hours ago
ilkkachuilkkachu
60.9k1098174
60.9k1098174
add a comment |
add a comment |
Steve is a new contributor. Be nice, and check out our Code of Conduct.
Steve is a new contributor. Be nice, and check out our Code of Conduct.
Steve is a new contributor. Be nice, and check out our Code of Conduct.
Steve is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505718%2fwhy-is-bash-checking-the-syntax-of-my-here-document-text%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
the code you posted does not generate those error messages; they're only generated if you leave out one of the single quotes from the sed command (
's/..//g'
)– mosvy
4 hours ago
I don't expect the error either but I am getting it 100% :) Using the code just like it is in my 2nd example above.
– Steve
3 hours ago
Steve I still cannot reproduce your error message. Unless @mosvy can spot the issue, would it be possible for you to post to actual script that you are running online (at pastebin.com or similar)? There may be some issue with encoding or the prior lines that we can't see here.
– John1024
3 hours ago
1
the only possibility left is that there's an unclosed quote somewhere before line 175, as explained in @ilkkachu's answer.
– mosvy
3 hours ago