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 `)'













0















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










share|improve this question



















  • 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 no elif in the code you show.

    – cdarke
    Mar 25 at 16:45















0















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










share|improve this question



















  • 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 no elif in the code you show.

    – cdarke
    Mar 25 at 16:45













0












0








0








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 gives elif but there is no elif in the code you show.

    – cdarke
    Mar 25 at 16:45












  • 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 no elif 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










2 Answers
2






active

oldest

votes


















0














This will do what you want:



#!/bin/bash

function add
echo $(( $1 + $2 ))


if [ $3 = '+' ]; then add $1 $2
fi





share|improve this answer























  • @emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)

    – Jona
    Mar 26 at 9:18


















0














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"






share|improve this answer

























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    This will do what you want:



    #!/bin/bash

    function add
    echo $(( $1 + $2 ))


    if [ $3 = '+' ]; then add $1 $2
    fi





    share|improve this answer























    • @emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)

      – Jona
      Mar 26 at 9:18















    0














    This will do what you want:



    #!/bin/bash

    function add
    echo $(( $1 + $2 ))


    if [ $3 = '+' ]; then add $1 $2
    fi





    share|improve this answer























    • @emma-brain If any of the answers solved your question, it's also a good practice to upvote. ;-)

      – Jona
      Mar 26 at 9:18













    0












    0








    0







    This will do what you want:



    #!/bin/bash

    function add
    echo $(( $1 + $2 ))


    if [ $3 = '+' ]; then add $1 $2
    fi





    share|improve this answer













    This will do what you want:



    #!/bin/bash

    function add
    echo $(( $1 + $2 ))


    if [ $3 = '+' ]; then add $1 $2
    fi






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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

















    • @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











    0














    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"






    share|improve this answer



























      0














      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"






      share|improve this answer

























        0












        0








        0







        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"






        share|improve this answer













        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"







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 16:38









        CorvarCorvar

        1




        1



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript