Syntax Error “elif” unexpected expecting thenDebugging Syntax error: “}” unexpected (expecting...
Is it standard for US-based universities to consider the ethnicity of an applicant during PhD admissions?
How long do Aarakocra live?
Why use a retrograde orbit?
What technology would Dwarves need to forge titanium?
How to handle professionally if colleagues has referred his relative and asking to take easy while taking interview
Write electromagnetic field tensor in terms of four-vector potential
Find the area of the rectangle
How to continually and organically let my readers know what time it is in my story?
Cannot remove door knob -- totally inaccessible!
When did Britain learn about American independence?
Is Big Ben visible from the British museum?
Why are lawsuits between the President and Congress not automatically sent to the Supreme Court
What would a Dragon have to exhale to cause rain?
Roman Numerals Equation 2
Divisor Rich and Poor Numbers
Why does the U.S military use mercenaries?
Why can't I share a one use code with anyone else?
What formula to chose a nonlinear formula?
Why is Drogon so much better in battle than Rhaegal and Viserion?
Capital gains on stocks sold to take initial investment off the table
How to deal with the extreme reverberation in big cathedrals when playing the pipe organs?
"Counterexample" for the Inverse function theorem
Why does string strummed with finger sound different from the one strummed with pick?
Resistor Selection to retain same brightness in LED PWM circuit
Syntax Error “elif” unexpected expecting then
Debugging Syntax error: “}” unexpected (expecting “fi”)Shellscript! Syntax error: unexpected “(”Unexpected EOF and syntax errorsyntax error near unexpected token `('User Input Shell Script Syntax Errorbash: syntax error near unexpected token `elif'Syntax error: “(” unexpected (expecting word) — in my bash scriptSyntax error, unexpected IDsyntax error near unexpected token `then'Syntax error when i use ssh with awk over bc
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
i am posting a new question to bugfix for my code.
if [ -f /etc/centos-release ]; then
OS="CentOs"
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
VER=${VERFULL:0:1} # return 6 or 7
elif [ -f /etc/lsb-release ]; then
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
elif [ -f /etc/os-release ]; then
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')
else
OS=$(uname -s)
VER=$(uname -r)
fi
Here elif [ -f /etc/lsb-release ]; then
code shows the error.
shell-script
add a comment |
i am posting a new question to bugfix for my code.
if [ -f /etc/centos-release ]; then
OS="CentOs"
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
VER=${VERFULL:0:1} # return 6 or 7
elif [ -f /etc/lsb-release ]; then
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
elif [ -f /etc/os-release ]; then
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')
else
OS=$(uname -s)
VER=$(uname -r)
fi
Here elif [ -f /etc/lsb-release ]; then
code shows the error.
shell-script
add a comment |
i am posting a new question to bugfix for my code.
if [ -f /etc/centos-release ]; then
OS="CentOs"
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
VER=${VERFULL:0:1} # return 6 or 7
elif [ -f /etc/lsb-release ]; then
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
elif [ -f /etc/os-release ]; then
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')
else
OS=$(uname -s)
VER=$(uname -r)
fi
Here elif [ -f /etc/lsb-release ]; then
code shows the error.
shell-script
i am posting a new question to bugfix for my code.
if [ -f /etc/centos-release ]; then
OS="CentOs"
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
VER=${VERFULL:0:1} # return 6 or 7
elif [ -f /etc/lsb-release ]; then
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
elif [ -f /etc/os-release ]; then
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')
else
OS=$(uname -s)
VER=$(uname -r)
fi
Here elif [ -f /etc/lsb-release ]; then
code shows the error.
shell-script
shell-script
edited Jan 26 at 16:10
Rui F Ribeiro
42.8k1486147
42.8k1486147
asked Jun 16 '18 at 18:01
KvvaradhaKvvaradha
1063
1063
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then
on the first line.
You could view your script with cat -A
to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A
will show line-feed characters as $
at the end of each line, control characters with the ^
prefix, and nonprintable characters with the 8th bit set with the M-
prefix. For example, TAB characters will show up as ^I
.
The cat -A
output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.
1
likely a carriage return (^M
) preventing the shell from recognizing thethen
at end of line
– ilkkachu
Jun 16 '18 at 19:03
That is one of the possibilities, yes; another common nuisance is Alt-space.cat -A
should catch them all.
– telcoM
Jun 16 '18 at 19:27
Tried it. Still the same issue comes.
– Kvvaradha
Jun 17 '18 at 3:50
add a comment |
That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.
$ cat -A x1
#!/bin/bash$
if [ -f /etc/centos-release ]; then$
OS="CentOs"$
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
VER=${VERFULL:0:1} # return 6 or 7$
elif [ -f /etc/lsb-release ]; then$
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
elif [ -f /etc/os-release ]; then$
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
else$
OS=$(uname -s)$
VER=$(uname -r)$
fi$
$ ./x1
$
I exactly used the same code in new . it results the same issue
– Kvvaradha
Jun 17 '18 at 3:51
add a comment |
I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.
New contributor
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
});
}
});
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%2f450179%2fsyntax-error-elif-unexpected-expecting-then%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
If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then
on the first line.
You could view your script with cat -A
to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A
will show line-feed characters as $
at the end of each line, control characters with the ^
prefix, and nonprintable characters with the 8th bit set with the M-
prefix. For example, TAB characters will show up as ^I
.
The cat -A
output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.
1
likely a carriage return (^M
) preventing the shell from recognizing thethen
at end of line
– ilkkachu
Jun 16 '18 at 19:03
That is one of the possibilities, yes; another common nuisance is Alt-space.cat -A
should catch them all.
– telcoM
Jun 16 '18 at 19:27
Tried it. Still the same issue comes.
– Kvvaradha
Jun 17 '18 at 3:50
add a comment |
If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then
on the first line.
You could view your script with cat -A
to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A
will show line-feed characters as $
at the end of each line, control characters with the ^
prefix, and nonprintable characters with the 8th bit set with the M-
prefix. For example, TAB characters will show up as ^I
.
The cat -A
output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.
1
likely a carriage return (^M
) preventing the shell from recognizing thethen
at end of line
– ilkkachu
Jun 16 '18 at 19:03
That is one of the possibilities, yes; another common nuisance is Alt-space.cat -A
should catch them all.
– telcoM
Jun 16 '18 at 19:27
Tried it. Still the same issue comes.
– Kvvaradha
Jun 17 '18 at 3:50
add a comment |
If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then
on the first line.
You could view your script with cat -A
to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A
will show line-feed characters as $
at the end of each line, control characters with the ^
prefix, and nonprintable characters with the 8th bit set with the M-
prefix. For example, TAB characters will show up as ^I
.
The cat -A
output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.
If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then
on the first line.
You could view your script with cat -A
to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A
will show line-feed characters as $
at the end of each line, control characters with the ^
prefix, and nonprintable characters with the 8th bit set with the M-
prefix. For example, TAB characters will show up as ^I
.
The cat -A
output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.
answered Jun 16 '18 at 18:12
telcoMtelcoM
21.8k12554
21.8k12554
1
likely a carriage return (^M
) preventing the shell from recognizing thethen
at end of line
– ilkkachu
Jun 16 '18 at 19:03
That is one of the possibilities, yes; another common nuisance is Alt-space.cat -A
should catch them all.
– telcoM
Jun 16 '18 at 19:27
Tried it. Still the same issue comes.
– Kvvaradha
Jun 17 '18 at 3:50
add a comment |
1
likely a carriage return (^M
) preventing the shell from recognizing thethen
at end of line
– ilkkachu
Jun 16 '18 at 19:03
That is one of the possibilities, yes; another common nuisance is Alt-space.cat -A
should catch them all.
– telcoM
Jun 16 '18 at 19:27
Tried it. Still the same issue comes.
– Kvvaradha
Jun 17 '18 at 3:50
1
1
likely a carriage return (
^M
) preventing the shell from recognizing the then
at end of line– ilkkachu
Jun 16 '18 at 19:03
likely a carriage return (
^M
) preventing the shell from recognizing the then
at end of line– ilkkachu
Jun 16 '18 at 19:03
That is one of the possibilities, yes; another common nuisance is Alt-space.
cat -A
should catch them all.– telcoM
Jun 16 '18 at 19:27
That is one of the possibilities, yes; another common nuisance is Alt-space.
cat -A
should catch them all.– telcoM
Jun 16 '18 at 19:27
Tried it. Still the same issue comes.
– Kvvaradha
Jun 17 '18 at 3:50
Tried it. Still the same issue comes.
– Kvvaradha
Jun 17 '18 at 3:50
add a comment |
That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.
$ cat -A x1
#!/bin/bash$
if [ -f /etc/centos-release ]; then$
OS="CentOs"$
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
VER=${VERFULL:0:1} # return 6 or 7$
elif [ -f /etc/lsb-release ]; then$
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
elif [ -f /etc/os-release ]; then$
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
else$
OS=$(uname -s)$
VER=$(uname -r)$
fi$
$ ./x1
$
I exactly used the same code in new . it results the same issue
– Kvvaradha
Jun 17 '18 at 3:51
add a comment |
That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.
$ cat -A x1
#!/bin/bash$
if [ -f /etc/centos-release ]; then$
OS="CentOs"$
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
VER=${VERFULL:0:1} # return 6 or 7$
elif [ -f /etc/lsb-release ]; then$
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
elif [ -f /etc/os-release ]; then$
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
else$
OS=$(uname -s)$
VER=$(uname -r)$
fi$
$ ./x1
$
I exactly used the same code in new . it results the same issue
– Kvvaradha
Jun 17 '18 at 3:51
add a comment |
That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.
$ cat -A x1
#!/bin/bash$
if [ -f /etc/centos-release ]; then$
OS="CentOs"$
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
VER=${VERFULL:0:1} # return 6 or 7$
elif [ -f /etc/lsb-release ]; then$
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
elif [ -f /etc/os-release ]; then$
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
else$
OS=$(uname -s)$
VER=$(uname -r)$
fi$
$ ./x1
$
That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.
$ cat -A x1
#!/bin/bash$
if [ -f /etc/centos-release ]; then$
OS="CentOs"$
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
VER=${VERFULL:0:1} # return 6 or 7$
elif [ -f /etc/lsb-release ]; then$
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
elif [ -f /etc/os-release ]; then$
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
else$
OS=$(uname -s)$
VER=$(uname -r)$
fi$
$ ./x1
$
answered Jun 16 '18 at 18:14
stevesteve
14.5k22854
14.5k22854
I exactly used the same code in new . it results the same issue
– Kvvaradha
Jun 17 '18 at 3:51
add a comment |
I exactly used the same code in new . it results the same issue
– Kvvaradha
Jun 17 '18 at 3:51
I exactly used the same code in new . it results the same issue
– Kvvaradha
Jun 17 '18 at 3:51
I exactly used the same code in new . it results the same issue
– Kvvaradha
Jun 17 '18 at 3:51
add a comment |
I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.
New contributor
add a comment |
I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.
New contributor
add a comment |
I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.
New contributor
I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.
New contributor
New contributor
answered 20 mins ago
LazorLazor
1011
1011
New contributor
New contributor
add a comment |
add a comment |
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%2f450179%2fsyntax-error-elif-unexpected-expecting-then%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