Missing fi's for if statements











up vote
0
down vote

favorite












I've written a script where I've got some nested-if statements.



if [ choice = "1" ]; then
if [ $package == *".tar.gz" ]; then //Could not find fi for this if
tar -zxvf folder.tar.gz
if [ $package == *".tar.bz2" ]; then
tar -xvfj folder.tar.bz2
./configure
make
make install
elif [ choice = "2" ]; then
dpkg -i package.deb
fi
//Expected fi


Have written where I get the fi errors in the script.










share|improve this question
























  • This script has a lot of mistakes. I recommend you to read a basic guide or an introduction before asking a question here.
    – zuazo
    Oct 11 '16 at 22:23

















up vote
0
down vote

favorite












I've written a script where I've got some nested-if statements.



if [ choice = "1" ]; then
if [ $package == *".tar.gz" ]; then //Could not find fi for this if
tar -zxvf folder.tar.gz
if [ $package == *".tar.bz2" ]; then
tar -xvfj folder.tar.bz2
./configure
make
make install
elif [ choice = "2" ]; then
dpkg -i package.deb
fi
//Expected fi


Have written where I get the fi errors in the script.










share|improve this question
























  • This script has a lot of mistakes. I recommend you to read a basic guide or an introduction before asking a question here.
    – zuazo
    Oct 11 '16 at 22:23















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I've written a script where I've got some nested-if statements.



if [ choice = "1" ]; then
if [ $package == *".tar.gz" ]; then //Could not find fi for this if
tar -zxvf folder.tar.gz
if [ $package == *".tar.bz2" ]; then
tar -xvfj folder.tar.bz2
./configure
make
make install
elif [ choice = "2" ]; then
dpkg -i package.deb
fi
//Expected fi


Have written where I get the fi errors in the script.










share|improve this question















I've written a script where I've got some nested-if statements.



if [ choice = "1" ]; then
if [ $package == *".tar.gz" ]; then //Could not find fi for this if
tar -zxvf folder.tar.gz
if [ $package == *".tar.bz2" ]; then
tar -xvfj folder.tar.bz2
./configure
make
make install
elif [ choice = "2" ]; then
dpkg -i package.deb
fi
//Expected fi


Have written where I get the fi errors in the script.







shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Rui F Ribeiro

38.6k1479128




38.6k1479128










asked Oct 11 '16 at 21:58









Hudhud

257




257












  • This script has a lot of mistakes. I recommend you to read a basic guide or an introduction before asking a question here.
    – zuazo
    Oct 11 '16 at 22:23




















  • This script has a lot of mistakes. I recommend you to read a basic guide or an introduction before asking a question here.
    – zuazo
    Oct 11 '16 at 22:23


















This script has a lot of mistakes. I recommend you to read a basic guide or an introduction before asking a question here.
– zuazo
Oct 11 '16 at 22:23






This script has a lot of mistakes. I recommend you to read a basic guide or an introduction before asking a question here.
– zuazo
Oct 11 '16 at 22:23












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










The basic structure for conditions is the following:



if [ condition ]; then
dosomething
fi


With else:



if [ condition ]; then
dosomething
elif [ condition ]; then
dootherthing
else
thelastchancetodosomething
fi


Also, I think this condition in your code is wrong:



if [ $package == *".tar.gz" ]; then
tar -zxvf folder.tar.gz
fi


If I'm understanding it correctly, it should be something like:



if echo $package | grep -qF ".tar.gz"; then
tar -zxvf $package
fi


Oh, and use # for comments instead of //.



Fixing your example and improving the indentation to be more clear:





if [ choice = "1" ]; then
if echo $package | grep -qF ".tar.gz"; then
tar -zxvf $package
# You need to close previous `if` with a `fi` you want to use another
# `if` here below, but we can use `elif`, so we don't need to close it.
elif echo $package | grep -qF ".tar.bz2"; then
tar -xvfj $package
fi
cd ${package%.*.*} # this removes the .tar.* extension
./configure
make
make install
elif [ choice = "2" ]; then
dpkg -i $package
fi





share|improve this answer




























    up vote
    1
    down vote













    That's a typical case where you'd want to use case:



    case $choice in
    (1)
    case $package in
    (*.tar.gz) tar -zxvf folder.tar.gz;;
    (*.tar.bz2) tar -jxvf folder.tar.bz2;;
    esac &&
    ./configure &&
    make &&
    make install
    ;;
    (2)
    dpkg -i package.deb
    ;;
    esac





    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: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      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%2funix.stackexchange.com%2fquestions%2f315763%2fmissing-fis-for-if-statements%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








      up vote
      0
      down vote



      accepted










      The basic structure for conditions is the following:



      if [ condition ]; then
      dosomething
      fi


      With else:



      if [ condition ]; then
      dosomething
      elif [ condition ]; then
      dootherthing
      else
      thelastchancetodosomething
      fi


      Also, I think this condition in your code is wrong:



      if [ $package == *".tar.gz" ]; then
      tar -zxvf folder.tar.gz
      fi


      If I'm understanding it correctly, it should be something like:



      if echo $package | grep -qF ".tar.gz"; then
      tar -zxvf $package
      fi


      Oh, and use # for comments instead of //.



      Fixing your example and improving the indentation to be more clear:





      if [ choice = "1" ]; then
      if echo $package | grep -qF ".tar.gz"; then
      tar -zxvf $package
      # You need to close previous `if` with a `fi` you want to use another
      # `if` here below, but we can use `elif`, so we don't need to close it.
      elif echo $package | grep -qF ".tar.bz2"; then
      tar -xvfj $package
      fi
      cd ${package%.*.*} # this removes the .tar.* extension
      ./configure
      make
      make install
      elif [ choice = "2" ]; then
      dpkg -i $package
      fi





      share|improve this answer

























        up vote
        0
        down vote



        accepted










        The basic structure for conditions is the following:



        if [ condition ]; then
        dosomething
        fi


        With else:



        if [ condition ]; then
        dosomething
        elif [ condition ]; then
        dootherthing
        else
        thelastchancetodosomething
        fi


        Also, I think this condition in your code is wrong:



        if [ $package == *".tar.gz" ]; then
        tar -zxvf folder.tar.gz
        fi


        If I'm understanding it correctly, it should be something like:



        if echo $package | grep -qF ".tar.gz"; then
        tar -zxvf $package
        fi


        Oh, and use # for comments instead of //.



        Fixing your example and improving the indentation to be more clear:





        if [ choice = "1" ]; then
        if echo $package | grep -qF ".tar.gz"; then
        tar -zxvf $package
        # You need to close previous `if` with a `fi` you want to use another
        # `if` here below, but we can use `elif`, so we don't need to close it.
        elif echo $package | grep -qF ".tar.bz2"; then
        tar -xvfj $package
        fi
        cd ${package%.*.*} # this removes the .tar.* extension
        ./configure
        make
        make install
        elif [ choice = "2" ]; then
        dpkg -i $package
        fi





        share|improve this answer























          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          The basic structure for conditions is the following:



          if [ condition ]; then
          dosomething
          fi


          With else:



          if [ condition ]; then
          dosomething
          elif [ condition ]; then
          dootherthing
          else
          thelastchancetodosomething
          fi


          Also, I think this condition in your code is wrong:



          if [ $package == *".tar.gz" ]; then
          tar -zxvf folder.tar.gz
          fi


          If I'm understanding it correctly, it should be something like:



          if echo $package | grep -qF ".tar.gz"; then
          tar -zxvf $package
          fi


          Oh, and use # for comments instead of //.



          Fixing your example and improving the indentation to be more clear:





          if [ choice = "1" ]; then
          if echo $package | grep -qF ".tar.gz"; then
          tar -zxvf $package
          # You need to close previous `if` with a `fi` you want to use another
          # `if` here below, but we can use `elif`, so we don't need to close it.
          elif echo $package | grep -qF ".tar.bz2"; then
          tar -xvfj $package
          fi
          cd ${package%.*.*} # this removes the .tar.* extension
          ./configure
          make
          make install
          elif [ choice = "2" ]; then
          dpkg -i $package
          fi





          share|improve this answer












          The basic structure for conditions is the following:



          if [ condition ]; then
          dosomething
          fi


          With else:



          if [ condition ]; then
          dosomething
          elif [ condition ]; then
          dootherthing
          else
          thelastchancetodosomething
          fi


          Also, I think this condition in your code is wrong:



          if [ $package == *".tar.gz" ]; then
          tar -zxvf folder.tar.gz
          fi


          If I'm understanding it correctly, it should be something like:



          if echo $package | grep -qF ".tar.gz"; then
          tar -zxvf $package
          fi


          Oh, and use # for comments instead of //.



          Fixing your example and improving the indentation to be more clear:





          if [ choice = "1" ]; then
          if echo $package | grep -qF ".tar.gz"; then
          tar -zxvf $package
          # You need to close previous `if` with a `fi` you want to use another
          # `if` here below, but we can use `elif`, so we don't need to close it.
          elif echo $package | grep -qF ".tar.bz2"; then
          tar -xvfj $package
          fi
          cd ${package%.*.*} # this removes the .tar.* extension
          ./configure
          make
          make install
          elif [ choice = "2" ]; then
          dpkg -i $package
          fi






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 11 '16 at 22:28









          zuazo

          2,179718




          2,179718
























              up vote
              1
              down vote













              That's a typical case where you'd want to use case:



              case $choice in
              (1)
              case $package in
              (*.tar.gz) tar -zxvf folder.tar.gz;;
              (*.tar.bz2) tar -jxvf folder.tar.bz2;;
              esac &&
              ./configure &&
              make &&
              make install
              ;;
              (2)
              dpkg -i package.deb
              ;;
              esac





              share|improve this answer

























                up vote
                1
                down vote













                That's a typical case where you'd want to use case:



                case $choice in
                (1)
                case $package in
                (*.tar.gz) tar -zxvf folder.tar.gz;;
                (*.tar.bz2) tar -jxvf folder.tar.bz2;;
                esac &&
                ./configure &&
                make &&
                make install
                ;;
                (2)
                dpkg -i package.deb
                ;;
                esac





                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  That's a typical case where you'd want to use case:



                  case $choice in
                  (1)
                  case $package in
                  (*.tar.gz) tar -zxvf folder.tar.gz;;
                  (*.tar.bz2) tar -jxvf folder.tar.bz2;;
                  esac &&
                  ./configure &&
                  make &&
                  make install
                  ;;
                  (2)
                  dpkg -i package.deb
                  ;;
                  esac





                  share|improve this answer












                  That's a typical case where you'd want to use case:



                  case $choice in
                  (1)
                  case $package in
                  (*.tar.gz) tar -zxvf folder.tar.gz;;
                  (*.tar.bz2) tar -jxvf folder.tar.bz2;;
                  esac &&
                  ./configure &&
                  make &&
                  make install
                  ;;
                  (2)
                  dpkg -i package.deb
                  ;;
                  esac






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 11 '16 at 22:35









                  Stéphane Chazelas

                  297k54562909




                  297k54562909






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


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





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2funix.stackexchange.com%2fquestions%2f315763%2fmissing-fis-for-if-statements%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

                      サソリ

                      広島県道265号伴広島線

                      Setup Asymptote in Texstudio