linux shell script Syntax error: word unexpected (expecting “fi”)Bash script throws “syntax error near unexpected token `}'” when runSyntax error near unexpected token `('Shell script If syntax errorline 42: syntax error: unexpected end of file-bash: syntax error near unexpected token `&'“bash: syntax error near unexpected ')” in Linux ShellSyntax error: word unexpected (expecting “)”)running simple bash script fails with Syntax error: word unexpected (expecting “)”)Bash script: syntax error near unexpected token `('unexpected EOF and syntax error:
"It doesn't matter" or "it won't matter"?
Why is so much work done on numerical verification of the Riemann Hypothesis?
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?
Can you use Vicious Mockery to win an argument or gain favours?
Can I cause damage to electrical appliances by unplugging them when they are turned on?
How to draw a matrix with arrows in limited space
A Trivial Diagnosis
How to get directions in deep space?
Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?
How to convince somebody that he is fit for something else, but not this job?
Shouldn’t conservatives embrace universal basic income?
Does Doodling or Improvising on the Piano Have Any Benefits?
Did the UK lift the requirement for registering SIM cards?
Will the Sticky MAC access policy prevent unauthorized hubs from connecting to a network?
When were female captains banned from Starfleet?
Review your own paper in Mathematics
15% tax on $7.5k earnings. Is that right?
Confused about Cramer-Rao lower bound and CLT
What is the difference between lands and mana?
What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?
Doesn't the system of the Supreme Court oppose justice?
What do you call a word that can be spelled forward or backward forming two different words
Why do Radio Buttons not fill the entire outer circle?
linux shell script Syntax error: word unexpected (expecting “fi”)
Bash script throws “syntax error near unexpected token `}'” when runSyntax error near unexpected token `('Shell script If syntax errorline 42: syntax error: unexpected end of file-bash: syntax error near unexpected token `&'“bash: syntax error near unexpected ')” in Linux ShellSyntax error: word unexpected (expecting “)”)running simple bash script fails with Syntax error: word unexpected (expecting “)”)Bash script: syntax error near unexpected token `('unexpected EOF and syntax error:
Below I have a shell script i wrote and when I try to execute it I get an error in my terminal describing the "expecting fi" keyword. I have written it down before the done keyword and have still not managed to overcome to error. Can anybody tell me as to how to solve this error and where in my approach I have made the mistake?
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do read -p "Enter values for both numbers" VAL1 VAL2
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then break
else read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then echo "Cannot divide by zero"
else echo $(( VAL1 / VAL2 ))
fi
done
command-line bash scripts gnome-terminal syntax
add a comment |
Below I have a shell script i wrote and when I try to execute it I get an error in my terminal describing the "expecting fi" keyword. I have written it down before the done keyword and have still not managed to overcome to error. Can anybody tell me as to how to solve this error and where in my approach I have made the mistake?
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do read -p "Enter values for both numbers" VAL1 VAL2
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then break
else read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then echo "Cannot divide by zero"
else echo $(( VAL1 / VAL2 ))
fi
done
command-line bash scripts gnome-terminal syntax
2
Well you have twoifs and only onefi, so onefiis missing – replace thefiline with:fi;fi
– dessert
2 hours ago
@dessert wow, i overlooked something so simple. Thanks dessert!
– Roosevelt Mendieta
2 hours ago
note: you can get a near debug mode with#!/bin/bash -xon the first line of your script OR by starting the script withbash -x ./myscript.sh
– cmak.fr
2 hours ago
another ex-COBOL coder eh? The fullstop kills all levels of IF doesn't apply to many other langauges (if any) :)
– guiverc
1 hour ago
add a comment |
Below I have a shell script i wrote and when I try to execute it I get an error in my terminal describing the "expecting fi" keyword. I have written it down before the done keyword and have still not managed to overcome to error. Can anybody tell me as to how to solve this error and where in my approach I have made the mistake?
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do read -p "Enter values for both numbers" VAL1 VAL2
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then break
else read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then echo "Cannot divide by zero"
else echo $(( VAL1 / VAL2 ))
fi
done
command-line bash scripts gnome-terminal syntax
Below I have a shell script i wrote and when I try to execute it I get an error in my terminal describing the "expecting fi" keyword. I have written it down before the done keyword and have still not managed to overcome to error. Can anybody tell me as to how to solve this error and where in my approach I have made the mistake?
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do read -p "Enter values for both numbers" VAL1 VAL2
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then break
else read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then echo "Cannot divide by zero"
else echo $(( VAL1 / VAL2 ))
fi
done
command-line bash scripts gnome-terminal syntax
command-line bash scripts gnome-terminal syntax
edited 2 hours ago
Pilot6
53.5k15109198
53.5k15109198
asked 2 hours ago
Roosevelt MendietaRoosevelt Mendieta
2014
2014
2
Well you have twoifs and only onefi, so onefiis missing – replace thefiline with:fi;fi
– dessert
2 hours ago
@dessert wow, i overlooked something so simple. Thanks dessert!
– Roosevelt Mendieta
2 hours ago
note: you can get a near debug mode with#!/bin/bash -xon the first line of your script OR by starting the script withbash -x ./myscript.sh
– cmak.fr
2 hours ago
another ex-COBOL coder eh? The fullstop kills all levels of IF doesn't apply to many other langauges (if any) :)
– guiverc
1 hour ago
add a comment |
2
Well you have twoifs and only onefi, so onefiis missing – replace thefiline with:fi;fi
– dessert
2 hours ago
@dessert wow, i overlooked something so simple. Thanks dessert!
– Roosevelt Mendieta
2 hours ago
note: you can get a near debug mode with#!/bin/bash -xon the first line of your script OR by starting the script withbash -x ./myscript.sh
– cmak.fr
2 hours ago
another ex-COBOL coder eh? The fullstop kills all levels of IF doesn't apply to many other langauges (if any) :)
– guiverc
1 hour ago
2
2
Well you have two
ifs and only one fi, so one fi is missing – replace the fi line with: fi;fi– dessert
2 hours ago
Well you have two
ifs and only one fi, so one fi is missing – replace the fi line with: fi;fi– dessert
2 hours ago
@dessert wow, i overlooked something so simple. Thanks dessert!
– Roosevelt Mendieta
2 hours ago
@dessert wow, i overlooked something so simple. Thanks dessert!
– Roosevelt Mendieta
2 hours ago
note: you can get a near debug mode with
#!/bin/bash -x on the first line of your script OR by starting the script with bash -x ./myscript.sh– cmak.fr
2 hours ago
note: you can get a near debug mode with
#!/bin/bash -x on the first line of your script OR by starting the script with bash -x ./myscript.sh– cmak.fr
2 hours ago
another ex-COBOL coder eh? The fullstop kills all levels of IF doesn't apply to many other langauges (if any) :)
– guiverc
1 hour ago
another ex-COBOL coder eh? The fullstop kills all levels of IF doesn't apply to many other langauges (if any) :)
– guiverc
1 hour ago
add a comment |
2 Answers
2
active
oldest
votes
“Expecting fi” means your script is missing this keyword. In your case you have two ifs, but only one fi, leaving the first unclosed. Correct it to:
else echo $(( VAL1 / VAL2 ))
fi
fi
done
In order to debug shell scripts it’s a good idea to use shellcheck either online or via the command shellcheck (sudo apt install shellcheck):
$ shellcheck myscript
Line 4:
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
^-- SC1009: The mentioned syntax error was in this while loop.
Line 6:
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
^-- SC1046: Couldn't find 'fi' for this 'if'.
^-- SC1073: Couldn't parse this if expression. Fix to allow more checks.
Line 13:
done
^-- SC1047: Expected 'fi' matching previously mentioned 'if'.
^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.
add a comment |
As dessert already pointed out, having two ifs but only one fi immediately tells you that there is a mismatch somewhere in your conditional statement.
One thing I would suggest is that when coding, it helps to use your indentation to help figure out if you are missing any structure. Keeping your if-then-else-fi within the same column is one trick that can be used to keep track of these things. Same for the case-esac or the do-done for that matter.
Using your sample code, if we indent in that manner, it's pretty clear with regards to something missing:
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do
read -p "Enter values for both numbers" VAL1
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then
break
else
read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then
echo "Cannot divide by zero"
else
echo $(( VAL1 / VAL2 ))
fi
?? <------ *Missing fi would likely have been detected here*
done
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f1127641%2flinux-shell-script-syntax-error-word-unexpected-expecting-fi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
“Expecting fi” means your script is missing this keyword. In your case you have two ifs, but only one fi, leaving the first unclosed. Correct it to:
else echo $(( VAL1 / VAL2 ))
fi
fi
done
In order to debug shell scripts it’s a good idea to use shellcheck either online or via the command shellcheck (sudo apt install shellcheck):
$ shellcheck myscript
Line 4:
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
^-- SC1009: The mentioned syntax error was in this while loop.
Line 6:
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
^-- SC1046: Couldn't find 'fi' for this 'if'.
^-- SC1073: Couldn't parse this if expression. Fix to allow more checks.
Line 13:
done
^-- SC1047: Expected 'fi' matching previously mentioned 'if'.
^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.
add a comment |
“Expecting fi” means your script is missing this keyword. In your case you have two ifs, but only one fi, leaving the first unclosed. Correct it to:
else echo $(( VAL1 / VAL2 ))
fi
fi
done
In order to debug shell scripts it’s a good idea to use shellcheck either online or via the command shellcheck (sudo apt install shellcheck):
$ shellcheck myscript
Line 4:
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
^-- SC1009: The mentioned syntax error was in this while loop.
Line 6:
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
^-- SC1046: Couldn't find 'fi' for this 'if'.
^-- SC1073: Couldn't parse this if expression. Fix to allow more checks.
Line 13:
done
^-- SC1047: Expected 'fi' matching previously mentioned 'if'.
^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.
add a comment |
“Expecting fi” means your script is missing this keyword. In your case you have two ifs, but only one fi, leaving the first unclosed. Correct it to:
else echo $(( VAL1 / VAL2 ))
fi
fi
done
In order to debug shell scripts it’s a good idea to use shellcheck either online or via the command shellcheck (sudo apt install shellcheck):
$ shellcheck myscript
Line 4:
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
^-- SC1009: The mentioned syntax error was in this while loop.
Line 6:
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
^-- SC1046: Couldn't find 'fi' for this 'if'.
^-- SC1073: Couldn't parse this if expression. Fix to allow more checks.
Line 13:
done
^-- SC1047: Expected 'fi' matching previously mentioned 'if'.
^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.
“Expecting fi” means your script is missing this keyword. In your case you have two ifs, but only one fi, leaving the first unclosed. Correct it to:
else echo $(( VAL1 / VAL2 ))
fi
fi
done
In order to debug shell scripts it’s a good idea to use shellcheck either online or via the command shellcheck (sudo apt install shellcheck):
$ shellcheck myscript
Line 4:
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
^-- SC1009: The mentioned syntax error was in this while loop.
Line 6:
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
^-- SC1046: Couldn't find 'fi' for this 'if'.
^-- SC1073: Couldn't parse this if expression. Fix to allow more checks.
Line 13:
done
^-- SC1047: Expected 'fi' matching previously mentioned 'if'.
^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.
answered 2 hours ago
dessertdessert
24.7k672105
24.7k672105
add a comment |
add a comment |
As dessert already pointed out, having two ifs but only one fi immediately tells you that there is a mismatch somewhere in your conditional statement.
One thing I would suggest is that when coding, it helps to use your indentation to help figure out if you are missing any structure. Keeping your if-then-else-fi within the same column is one trick that can be used to keep track of these things. Same for the case-esac or the do-done for that matter.
Using your sample code, if we indent in that manner, it's pretty clear with regards to something missing:
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do
read -p "Enter values for both numbers" VAL1
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then
break
else
read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then
echo "Cannot divide by zero"
else
echo $(( VAL1 / VAL2 ))
fi
?? <------ *Missing fi would likely have been detected here*
done
add a comment |
As dessert already pointed out, having two ifs but only one fi immediately tells you that there is a mismatch somewhere in your conditional statement.
One thing I would suggest is that when coding, it helps to use your indentation to help figure out if you are missing any structure. Keeping your if-then-else-fi within the same column is one trick that can be used to keep track of these things. Same for the case-esac or the do-done for that matter.
Using your sample code, if we indent in that manner, it's pretty clear with regards to something missing:
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do
read -p "Enter values for both numbers" VAL1
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then
break
else
read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then
echo "Cannot divide by zero"
else
echo $(( VAL1 / VAL2 ))
fi
?? <------ *Missing fi would likely have been detected here*
done
add a comment |
As dessert already pointed out, having two ifs but only one fi immediately tells you that there is a mismatch somewhere in your conditional statement.
One thing I would suggest is that when coding, it helps to use your indentation to help figure out if you are missing any structure. Keeping your if-then-else-fi within the same column is one trick that can be used to keep track of these things. Same for the case-esac or the do-done for that matter.
Using your sample code, if we indent in that manner, it's pretty clear with regards to something missing:
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do
read -p "Enter values for both numbers" VAL1
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then
break
else
read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then
echo "Cannot divide by zero"
else
echo $(( VAL1 / VAL2 ))
fi
?? <------ *Missing fi would likely have been detected here*
done
As dessert already pointed out, having two ifs but only one fi immediately tells you that there is a mismatch somewhere in your conditional statement.
One thing I would suggest is that when coding, it helps to use your indentation to help figure out if you are missing any structure. Keeping your if-then-else-fi within the same column is one trick that can be used to keep track of these things. Same for the case-esac or the do-done for that matter.
Using your sample code, if we indent in that manner, it's pretty clear with regards to something missing:
VAL1=0
VAL2=0
while [ "$VAL1" -eq 0 ] && [ "$VAL2" -eq 0 ]
do
read -p "Enter values for both numbers" VAL1
if [ "$VAL1" -eq 99 ] || [ "$VAL1" -eq 99 ]
then
break
else
read -p "Enter value number two" VAL2
if [ "$VAL2" -eq 0 ]
then
echo "Cannot divide by zero"
else
echo $(( VAL1 / VAL2 ))
fi
?? <------ *Missing fi would likely have been detected here*
done
answered 2 hours ago
S. NixonS. Nixon
233
233
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1127641%2flinux-shell-script-syntax-error-word-unexpected-expecting-fi%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
2
Well you have two
ifs and only onefi, so onefiis missing – replace thefiline with:fi;fi– dessert
2 hours ago
@dessert wow, i overlooked something so simple. Thanks dessert!
– Roosevelt Mendieta
2 hours ago
note: you can get a near debug mode with
#!/bin/bash -xon the first line of your script OR by starting the script withbash -x ./myscript.sh– cmak.fr
2 hours ago
another ex-COBOL coder eh? The fullstop kills all levels of IF doesn't apply to many other langauges (if any) :)
– guiverc
1 hour ago