Syntax error near unexpected token 'elif' in Bashif, elif, else statement issues in BashUbuntu BASH syntax error near unexpected tokenmakefile in ubuntu giving bash syntax error near unexpected token `(syntax error in bash “if.. elif” scriptBash Script if elif elif not workingsh.exe": syntax error near unexpected token `('Bash: Syntax Error Near Unexpected Token `(' When Using Wgrib2BASH: syntax error near unexpected token `(' in .bashrcBash scripting: syntax error near unexpected token `done'Getting an error syntax error near unexpected token `then'bash: syntax error near unexpected token `)'
Is this house-rule removing the increased effect of cantrips at higher character levels balanced?
Is it advisable to inform the CEO about his brother accessing his office?
What are the children of two Muggle-borns called?
Drawing a sigmoid function and its derivative in tikz
"I am [the / an] owner of a bookstore"?
"in 60 seconds or less" or "in 60 seconds or fewer"?
Why will we fail creating a self sustaining off world colony?
Tricolour nonogram
Does a lens with a bigger max. aperture focus faster than a lens with a smaller max. aperture?
Having to constantly redo everything because I don't know how to do it
ATMEGA328P-U vs ATMEGA328-PU
Why is my 401k manager recommending me to save more?
Have any large aeroplanes been landed — safely and without damage — in locations that they could not be flown away from?
How far can gerrymandering go?
Simplify the code
Where to connect the fuse and why?
What prevents a US state from colonizing a smaller state?
What was the first science fiction or fantasy multiple choice book?
What is the meaning of "it" in "as luck would have it"?
Five 5-cent coins touching each other
Apollo Mission Operations Control Room 2 display, what do these numbers indicate?
Does friction always oppose motion?
Chandra exiles a card, I play it, it gets exiled again
A quine of sorts
Syntax error near unexpected token 'elif' in Bash
if, elif, else statement issues in BashUbuntu BASH syntax error near unexpected tokenmakefile in ubuntu giving bash syntax error near unexpected token `(syntax error in bash “if.. elif” scriptBash Script if elif elif not workingsh.exe": syntax error near unexpected token `('Bash: Syntax Error Near Unexpected Token `(' When Using Wgrib2BASH: syntax error near unexpected token `(' in .bashrcBash scripting: syntax error near unexpected token `done'Getting an error syntax error near unexpected token `then'bash: syntax error near unexpected token `)'
I'm using a new language, I think it's linux but to be honest I have no clue; we're connecting to some server through a program called putty to do this programming. As part of an assignment I have to create a calculator program that takes two numbers and an operator as arugments but I'm getting a bunch of unexpected token errors. I'm very lost and neither my text no my professor is helpful so far
#!/bin/bash
function add
echo $(( $1 + $2 ))
function subtract
echo $(( $1 - $2 ))
function multiply
echo $(( $1 x $2 ))
function divide
echo $(( $1 / $2 ))
if [ $3 = '+' ] then add
so far I'm just trying to get it so I can get 2 from the command ./calc.sh 1 1 + but I keep getting unexpected token error on line 20 syntax error near unexpected token 'elif' [ $3 = '-' ]
then subtract
linux bash
add a comment |
I'm using a new language, I think it's linux but to be honest I have no clue; we're connecting to some server through a program called putty to do this programming. As part of an assignment I have to create a calculator program that takes two numbers and an operator as arugments but I'm getting a bunch of unexpected token errors. I'm very lost and neither my text no my professor is helpful so far
#!/bin/bash
function add
echo $(( $1 + $2 ))
function subtract
echo $(( $1 - $2 ))
function multiply
echo $(( $1 x $2 ))
function divide
echo $(( $1 / $2 ))
if [ $3 = '+' ] then add
so far I'm just trying to get it so I can get 2 from the command ./calc.sh 1 1 + but I keep getting unexpected token error on line 20 syntax error near unexpected token 'elif' [ $3 = '-' ]
then subtract
linux bash
3
You didn't include the code that the error is referencing.
– Carcigenicate
Mar 25 at 16:33
1
The language you are mentioning is not "linux", it's "bash".
– Jona
Mar 25 at 16:36
1
Please show the relevant code. Please state where the error is encountered. Also see if, elif, else statement issues in Bash and How to create a Minimal, Complete, and Verifiable example.
– jww
Mar 25 at 16:41
1
Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.
– jww
Mar 25 at 16:41
1
Your error messages giveselif
but there is noelif
in the code you show.
– cdarke
Mar 25 at 16:45
add a comment |
I'm using a new language, I think it's linux but to be honest I have no clue; we're connecting to some server through a program called putty to do this programming. As part of an assignment I have to create a calculator program that takes two numbers and an operator as arugments but I'm getting a bunch of unexpected token errors. I'm very lost and neither my text no my professor is helpful so far
#!/bin/bash
function add
echo $(( $1 + $2 ))
function subtract
echo $(( $1 - $2 ))
function multiply
echo $(( $1 x $2 ))
function divide
echo $(( $1 / $2 ))
if [ $3 = '+' ] then add
so far I'm just trying to get it so I can get 2 from the command ./calc.sh 1 1 + but I keep getting unexpected token error on line 20 syntax error near unexpected token 'elif' [ $3 = '-' ]
then subtract
linux bash
I'm using a new language, I think it's linux but to be honest I have no clue; we're connecting to some server through a program called putty to do this programming. As part of an assignment I have to create a calculator program that takes two numbers and an operator as arugments but I'm getting a bunch of unexpected token errors. I'm very lost and neither my text no my professor is helpful so far
#!/bin/bash
function add
echo $(( $1 + $2 ))
function subtract
echo $(( $1 - $2 ))
function multiply
echo $(( $1 x $2 ))
function divide
echo $(( $1 / $2 ))
if [ $3 = '+' ] then add
so far I'm just trying to get it so I can get 2 from the command ./calc.sh 1 1 + but I keep getting unexpected token error on line 20 syntax error near unexpected token 'elif' [ $3 = '-' ]
then subtract
linux bash
linux bash
edited Mar 25 at 16:44


jww
56.1k42 gold badges247 silver badges540 bronze badges
56.1k42 gold badges247 silver badges540 bronze badges
asked Mar 25 at 16:29
emma brainemma brain
319 bronze badges
319 bronze badges
3
You didn't include the code that the error is referencing.
– Carcigenicate
Mar 25 at 16:33
1
The language you are mentioning is not "linux", it's "bash".
– Jona
Mar 25 at 16:36
1
Please show the relevant code. Please state where the error is encountered. Also see if, elif, else statement issues in Bash and How to create a Minimal, Complete, and Verifiable example.
– jww
Mar 25 at 16:41
1
Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.
– jww
Mar 25 at 16:41
1
Your error messages giveselif
but there is noelif
in the code you show.
– cdarke
Mar 25 at 16:45
add a comment |
3
You didn't include the code that the error is referencing.
– Carcigenicate
Mar 25 at 16:33
1
The language you are mentioning is not "linux", it's "bash".
– Jona
Mar 25 at 16:36
1
Please show the relevant code. Please state where the error is encountered. Also see if, elif, else statement issues in Bash and How to create a Minimal, Complete, and Verifiable example.
– jww
Mar 25 at 16:41
1
Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.
– jww
Mar 25 at 16:41
1
Your error messages giveselif
but there is noelif
in the code you show.
– cdarke
Mar 25 at 16:45
3
3
You didn't include the code that the error is referencing.
– Carcigenicate
Mar 25 at 16:33
You didn't include the code that the error is referencing.
– Carcigenicate
Mar 25 at 16:33
1
1
The language you are mentioning is not "linux", it's "bash".
– Jona
Mar 25 at 16:36
The language you are mentioning is not "linux", it's "bash".
– Jona
Mar 25 at 16:36
1
1
Please show the relevant code. Please state where the error is encountered. Also see if, elif, else statement issues in Bash and How to create a Minimal, Complete, and Verifiable example.
– jww
Mar 25 at 16:41
Please show the relevant code. Please state where the error is encountered. Also see if, elif, else statement issues in Bash and How to create a Minimal, Complete, and Verifiable example.
– jww
Mar 25 at 16:41
1
1
Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.
– jww
Mar 25 at 16:41
Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.
– jww
Mar 25 at 16:41
1
1
Your error messages gives
elif
but there is no elif
in the code you show.– cdarke
Mar 25 at 16:45
Your error messages gives
elif
but there is no elif
in the code you show.– cdarke
Mar 25 at 16:45
add a comment |
2 Answers
2
active
oldest
votes
This will do what you want:
#!/bin/bash
function add
echo $(( $1 + $2 ))
if [ $3 = '+' ]; then add $1 $2
fi
@emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)
– Jona
Mar 26 at 9:18
add a comment |
There are a number of issues in just what we can see, in the last visible line.
You need either a line break or a semi colon after if [ $3 = '+' ]
And while it is possible that it is just where it chose to stop pasting, your functions need to be passed arguments, so "add $1 $2" vs "add"
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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%2fstackoverflow.com%2fquestions%2f55342380%2fsyntax-error-near-unexpected-token-elif-in-bash%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
This will do what you want:
#!/bin/bash
function add
echo $(( $1 + $2 ))
if [ $3 = '+' ]; then add $1 $2
fi
@emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)
– Jona
Mar 26 at 9:18
add a comment |
This will do what you want:
#!/bin/bash
function add
echo $(( $1 + $2 ))
if [ $3 = '+' ]; then add $1 $2
fi
@emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)
– Jona
Mar 26 at 9:18
add a comment |
This will do what you want:
#!/bin/bash
function add
echo $(( $1 + $2 ))
if [ $3 = '+' ]; then add $1 $2
fi
This will do what you want:
#!/bin/bash
function add
echo $(( $1 + $2 ))
if [ $3 = '+' ]; then add $1 $2
fi
answered Mar 25 at 16:43


JonaJona
2931 gold badge2 silver badges10 bronze badges
2931 gold badge2 silver badges10 bronze badges
@emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)
– Jona
Mar 26 at 9:18
add a comment |
@emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)
– Jona
Mar 26 at 9:18
@emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)
– Jona
Mar 26 at 9:18
@emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)
– Jona
Mar 26 at 9:18
add a comment |
There are a number of issues in just what we can see, in the last visible line.
You need either a line break or a semi colon after if [ $3 = '+' ]
And while it is possible that it is just where it chose to stop pasting, your functions need to be passed arguments, so "add $1 $2" vs "add"
add a comment |
There are a number of issues in just what we can see, in the last visible line.
You need either a line break or a semi colon after if [ $3 = '+' ]
And while it is possible that it is just where it chose to stop pasting, your functions need to be passed arguments, so "add $1 $2" vs "add"
add a comment |
There are a number of issues in just what we can see, in the last visible line.
You need either a line break or a semi colon after if [ $3 = '+' ]
And while it is possible that it is just where it chose to stop pasting, your functions need to be passed arguments, so "add $1 $2" vs "add"
There are a number of issues in just what we can see, in the last visible line.
You need either a line break or a semi colon after if [ $3 = '+' ]
And while it is possible that it is just where it chose to stop pasting, your functions need to be passed arguments, so "add $1 $2" vs "add"
answered Mar 25 at 16:38
CorvarCorvar
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55342380%2fsyntax-error-near-unexpected-token-elif-in-bash%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
3
You didn't include the code that the error is referencing.
– Carcigenicate
Mar 25 at 16:33
1
The language you are mentioning is not "linux", it's "bash".
– Jona
Mar 25 at 16:36
1
Please show the relevant code. Please state where the error is encountered. Also see if, elif, else statement issues in Bash and How to create a Minimal, Complete, and Verifiable example.
– jww
Mar 25 at 16:41
1
Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.
– jww
Mar 25 at 16:41
1
Your error messages gives
elif
but there is noelif
in the code you show.– cdarke
Mar 25 at 16:45