Bash Syntax Error Missing expecting “then”

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












For the following lines in my Makefile I get the error



Syntax error: end of file unexpected (expecting "then")


Code:



if [ ! -d upload-api/app-router/ ] then
git clone someRepo upload-api/app-router/
fi


I've tried with a semicolon after the brackets but I get still the same error







share|improve this question
























    up vote
    3
    down vote

    favorite












    For the following lines in my Makefile I get the error



    Syntax error: end of file unexpected (expecting "then")


    Code:



    if [ ! -d upload-api/app-router/ ] then
    git clone someRepo upload-api/app-router/
    fi


    I've tried with a semicolon after the brackets but I get still the same error







    share|improve this question






















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      For the following lines in my Makefile I get the error



      Syntax error: end of file unexpected (expecting "then")


      Code:



      if [ ! -d upload-api/app-router/ ] then
      git clone someRepo upload-api/app-router/
      fi


      I've tried with a semicolon after the brackets but I get still the same error







      share|improve this question












      For the following lines in my Makefile I get the error



      Syntax error: end of file unexpected (expecting "then")


      Code:



      if [ ! -d upload-api/app-router/ ] then
      git clone someRepo upload-api/app-router/
      fi


      I've tried with a semicolon after the brackets but I get still the same error









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 21 at 8:40









      Barsch

      192




      192




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          14
          down vote













          You need to put then in next line or use semicolon



          if [ ! -d upload-api/app-router/ ] 
          then


          or



          if [ ! -d upload-api/app-router/ ];then





          share|improve this answer


















          • 1




            Note that the spaces before and after ; are optional, if [ ! -d upload-api/app-router/ ];then (or any combination) is equally valid.
            – dessert
            Aug 21 at 8:50







          • 1




            Totally agree ...
            – papampi
            Aug 21 at 8:56

















          up vote
          3
          down vote













          In the context of a makefile, I see two things.



          First, you need a semicolon or newline before the then. Shell syntax for if looks like: if commands... ; then commands... ; fi (where any semicolon here can be replaced with a newline).



          Second, when make executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:



          sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
          sh -c 'git clone someRepo upload-api/app-router/' &&
          sh -c 'fi'


          ...which is a syntax error on the first line, with or without the semicolon, because the if is never finished.



          So for a makefile recipe, you would need to let make know that it should treat the entire if ... fi block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.



          my-target:
          ↦ if [ ! -d upload-api/app-router/ ] ; then
          ↦ git clone someRepo upload-api/app-router/ ;
          ↦ fi


          This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.






          share|improve this answer






















            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',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1067414%2fbash-syntax-error-missing-expecting-then%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            14
            down vote













            You need to put then in next line or use semicolon



            if [ ! -d upload-api/app-router/ ] 
            then


            or



            if [ ! -d upload-api/app-router/ ];then





            share|improve this answer


















            • 1




              Note that the spaces before and after ; are optional, if [ ! -d upload-api/app-router/ ];then (or any combination) is equally valid.
              – dessert
              Aug 21 at 8:50







            • 1




              Totally agree ...
              – papampi
              Aug 21 at 8:56














            up vote
            14
            down vote













            You need to put then in next line or use semicolon



            if [ ! -d upload-api/app-router/ ] 
            then


            or



            if [ ! -d upload-api/app-router/ ];then





            share|improve this answer


















            • 1




              Note that the spaces before and after ; are optional, if [ ! -d upload-api/app-router/ ];then (or any combination) is equally valid.
              – dessert
              Aug 21 at 8:50







            • 1




              Totally agree ...
              – papampi
              Aug 21 at 8:56












            up vote
            14
            down vote










            up vote
            14
            down vote









            You need to put then in next line or use semicolon



            if [ ! -d upload-api/app-router/ ] 
            then


            or



            if [ ! -d upload-api/app-router/ ];then





            share|improve this answer














            You need to put then in next line or use semicolon



            if [ ! -d upload-api/app-router/ ] 
            then


            or



            if [ ! -d upload-api/app-router/ ];then






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 21 at 8:56

























            answered Aug 21 at 8:46









            papampi

            318210




            318210







            • 1




              Note that the spaces before and after ; are optional, if [ ! -d upload-api/app-router/ ];then (or any combination) is equally valid.
              – dessert
              Aug 21 at 8:50







            • 1




              Totally agree ...
              – papampi
              Aug 21 at 8:56












            • 1




              Note that the spaces before and after ; are optional, if [ ! -d upload-api/app-router/ ];then (or any combination) is equally valid.
              – dessert
              Aug 21 at 8:50







            • 1




              Totally agree ...
              – papampi
              Aug 21 at 8:56







            1




            1




            Note that the spaces before and after ; are optional, if [ ! -d upload-api/app-router/ ];then (or any combination) is equally valid.
            – dessert
            Aug 21 at 8:50





            Note that the spaces before and after ; are optional, if [ ! -d upload-api/app-router/ ];then (or any combination) is equally valid.
            – dessert
            Aug 21 at 8:50





            1




            1




            Totally agree ...
            – papampi
            Aug 21 at 8:56




            Totally agree ...
            – papampi
            Aug 21 at 8:56












            up vote
            3
            down vote













            In the context of a makefile, I see two things.



            First, you need a semicolon or newline before the then. Shell syntax for if looks like: if commands... ; then commands... ; fi (where any semicolon here can be replaced with a newline).



            Second, when make executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:



            sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
            sh -c 'git clone someRepo upload-api/app-router/' &&
            sh -c 'fi'


            ...which is a syntax error on the first line, with or without the semicolon, because the if is never finished.



            So for a makefile recipe, you would need to let make know that it should treat the entire if ... fi block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.



            my-target:
            ↦ if [ ! -d upload-api/app-router/ ] ; then
            ↦ git clone someRepo upload-api/app-router/ ;
            ↦ fi


            This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.






            share|improve this answer


























              up vote
              3
              down vote













              In the context of a makefile, I see two things.



              First, you need a semicolon or newline before the then. Shell syntax for if looks like: if commands... ; then commands... ; fi (where any semicolon here can be replaced with a newline).



              Second, when make executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:



              sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
              sh -c 'git clone someRepo upload-api/app-router/' &&
              sh -c 'fi'


              ...which is a syntax error on the first line, with or without the semicolon, because the if is never finished.



              So for a makefile recipe, you would need to let make know that it should treat the entire if ... fi block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.



              my-target:
              ↦ if [ ! -d upload-api/app-router/ ] ; then
              ↦ git clone someRepo upload-api/app-router/ ;
              ↦ fi


              This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.






              share|improve this answer
























                up vote
                3
                down vote










                up vote
                3
                down vote









                In the context of a makefile, I see two things.



                First, you need a semicolon or newline before the then. Shell syntax for if looks like: if commands... ; then commands... ; fi (where any semicolon here can be replaced with a newline).



                Second, when make executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:



                sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
                sh -c 'git clone someRepo upload-api/app-router/' &&
                sh -c 'fi'


                ...which is a syntax error on the first line, with or without the semicolon, because the if is never finished.



                So for a makefile recipe, you would need to let make know that it should treat the entire if ... fi block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.



                my-target:
                ↦ if [ ! -d upload-api/app-router/ ] ; then
                ↦ git clone someRepo upload-api/app-router/ ;
                ↦ fi


                This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.






                share|improve this answer














                In the context of a makefile, I see two things.



                First, you need a semicolon or newline before the then. Shell syntax for if looks like: if commands... ; then commands... ; fi (where any semicolon here can be replaced with a newline).



                Second, when make executes a recipe, it runs each individual line of the recipe in a separate shell instance, and stops executing if any single line gives an error. Effectively, it's running:



                sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
                sh -c 'git clone someRepo upload-api/app-router/' &&
                sh -c 'fi'


                ...which is a syntax error on the first line, with or without the semicolon, because the if is never finished.



                So for a makefile recipe, you would need to let make know that it should treat the entire if ... fi block as one line. For instance, use backslashes for line continuation, and semicolons in the appropriate places since the shell won't see any line breaks.



                my-target:
                ↦ if [ ! -d upload-api/app-router/ ] ; then
                ↦ git clone someRepo upload-api/app-router/ ;
                ↦ fi


                This gets unwieldy pretty quickly, so my preferred solution is usually to put the shellscript in a separate file, then run that file from your recipe.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 21 at 18:34

























                answered Aug 21 at 18:25









                Jander

                1512




                1512



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1067414%2fbash-syntax-error-missing-expecting-then%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery