Makefile not accepting conditionals

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











up vote
-1
down vote

favorite












I am using the following conditional statement within a Makefile:



mytarget:
if [ -z "$TAG1" | -z "$TAG2" | -z "$TAG3" ]
then
echo "Need to set all tag names images
exit 1
fi


but then ...



$ make mytarget TAG1=latest TAG2=latest TAG3=latest
if [ -z "latest" | -z "latest" | -z "latest" ]
/bin/bash: -c: line 1: syntax error: unexpected end of file
Makefile:36: recipe for target 'env' failed
make: *** [env] Error 1






share|improve this question























    up vote
    -1
    down vote

    favorite












    I am using the following conditional statement within a Makefile:



    mytarget:
    if [ -z "$TAG1" | -z "$TAG2" | -z "$TAG3" ]
    then
    echo "Need to set all tag names images
    exit 1
    fi


    but then ...



    $ make mytarget TAG1=latest TAG2=latest TAG3=latest
    if [ -z "latest" | -z "latest" | -z "latest" ]
    /bin/bash: -c: line 1: syntax error: unexpected end of file
    Makefile:36: recipe for target 'env' failed
    make: *** [env] Error 1






    share|improve this question





















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I am using the following conditional statement within a Makefile:



      mytarget:
      if [ -z "$TAG1" | -z "$TAG2" | -z "$TAG3" ]
      then
      echo "Need to set all tag names images
      exit 1
      fi


      but then ...



      $ make mytarget TAG1=latest TAG2=latest TAG3=latest
      if [ -z "latest" | -z "latest" | -z "latest" ]
      /bin/bash: -c: line 1: syntax error: unexpected end of file
      Makefile:36: recipe for target 'env' failed
      make: *** [env] Error 1






      share|improve this question











      I am using the following conditional statement within a Makefile:



      mytarget:
      if [ -z "$TAG1" | -z "$TAG2" | -z "$TAG3" ]
      then
      echo "Need to set all tag names images
      exit 1
      fi


      but then ...



      $ make mytarget TAG1=latest TAG2=latest TAG3=latest
      if [ -z "latest" | -z "latest" | -z "latest" ]
      /bin/bash: -c: line 1: syntax error: unexpected end of file
      Makefile:36: recipe for target 'env' failed
      make: *** [env] Error 1








      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 28 at 11:14









      pkaramol

      201111




      201111




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You need to have backslashes at the end of each (but the last) command line.



          make sends each command line to a separate shell using: /bin/sh -ce "cmdline"



          Note that since you don't have the newlines in the shell anymore, you may need to add a semicolon at before the backslash newline for some commands, e.g.



          target:
          if true;
          then
          echo true;
          fi


          the backslash causes that make converts all these virtual lines to:



          if true; then echo true; fi


          before sending it to /bin/sh -ce cmd.






          share|improve this answer























            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f452413%2fmakefile-not-accepting-conditionals%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            You need to have backslashes at the end of each (but the last) command line.



            make sends each command line to a separate shell using: /bin/sh -ce "cmdline"



            Note that since you don't have the newlines in the shell anymore, you may need to add a semicolon at before the backslash newline for some commands, e.g.



            target:
            if true;
            then
            echo true;
            fi


            the backslash causes that make converts all these virtual lines to:



            if true; then echo true; fi


            before sending it to /bin/sh -ce cmd.






            share|improve this answer



























              up vote
              0
              down vote













              You need to have backslashes at the end of each (but the last) command line.



              make sends each command line to a separate shell using: /bin/sh -ce "cmdline"



              Note that since you don't have the newlines in the shell anymore, you may need to add a semicolon at before the backslash newline for some commands, e.g.



              target:
              if true;
              then
              echo true;
              fi


              the backslash causes that make converts all these virtual lines to:



              if true; then echo true; fi


              before sending it to /bin/sh -ce cmd.






              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote









                You need to have backslashes at the end of each (but the last) command line.



                make sends each command line to a separate shell using: /bin/sh -ce "cmdline"



                Note that since you don't have the newlines in the shell anymore, you may need to add a semicolon at before the backslash newline for some commands, e.g.



                target:
                if true;
                then
                echo true;
                fi


                the backslash causes that make converts all these virtual lines to:



                if true; then echo true; fi


                before sending it to /bin/sh -ce cmd.






                share|improve this answer















                You need to have backslashes at the end of each (but the last) command line.



                make sends each command line to a separate shell using: /bin/sh -ce "cmdline"



                Note that since you don't have the newlines in the shell anymore, you may need to add a semicolon at before the backslash newline for some commands, e.g.



                target:
                if true;
                then
                echo true;
                fi


                the backslash causes that make converts all these virtual lines to:



                if true; then echo true; fi


                before sending it to /bin/sh -ce cmd.







                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jun 28 at 15:10


























                answered Jun 28 at 11:23









                schily

                8,57421435




                8,57421435






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452413%2fmakefile-not-accepting-conditionals%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)