Syntax Error “elif” unexpected expecting thenDebugging Syntax error: “}” unexpected (expecting...

Is it standard for US-based universities to consider the ethnicity of an applicant during PhD admissions?

How long do Aarakocra live?

Why use a retrograde orbit?

What technology would Dwarves need to forge titanium?

How to handle professionally if colleagues has referred his relative and asking to take easy while taking interview

Write electromagnetic field tensor in terms of four-vector potential

Find the area of the rectangle

How to continually and organically let my readers know what time it is in my story?

Cannot remove door knob -- totally inaccessible!

When did Britain learn about American independence?

Is Big Ben visible from the British museum?

Why are lawsuits between the President and Congress not automatically sent to the Supreme Court

What would a Dragon have to exhale to cause rain?

Roman Numerals Equation 2

Divisor Rich and Poor Numbers

Why does the U.S military use mercenaries?

Why can't I share a one use code with anyone else?

What formula to chose a nonlinear formula?

Why is Drogon so much better in battle than Rhaegal and Viserion?

Capital gains on stocks sold to take initial investment off the table

How to deal with the extreme reverberation in big cathedrals when playing the pipe organs?

"Counterexample" for the Inverse function theorem

Why does string strummed with finger sound different from the one strummed with pick?

Resistor Selection to retain same brightness in LED PWM circuit



Syntax Error “elif” unexpected expecting then


Debugging Syntax error: “}” unexpected (expecting “fi”)Shellscript! Syntax error: unexpected “(”Unexpected EOF and syntax errorsyntax error near unexpected token `('User Input Shell Script Syntax Errorbash: syntax error near unexpected token `elif'Syntax error: “(” unexpected (expecting word) — in my bash scriptSyntax error, unexpected IDsyntax error near unexpected token `then'Syntax error when i use ssh with awk over bc






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















i am posting a new question to bugfix for my code.



    if [ -f /etc/centos-release ]; then
OS="CentOs"
VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
VER=${VERFULL:0:1} # return 6 or 7
elif [ -f /etc/lsb-release ]; then
OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
elif [ -f /etc/os-release ]; then
OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')
VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')
else
OS=$(uname -s)
VER=$(uname -r)
fi


Here elif [ -f /etc/lsb-release ]; then code shows the error.










share|improve this question































    0















    i am posting a new question to bugfix for my code.



        if [ -f /etc/centos-release ]; then
    OS="CentOs"
    VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
    VER=${VERFULL:0:1} # return 6 or 7
    elif [ -f /etc/lsb-release ]; then
    OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
    VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
    elif [ -f /etc/os-release ]; then
    OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')
    VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')
    else
    OS=$(uname -s)
    VER=$(uname -r)
    fi


    Here elif [ -f /etc/lsb-release ]; then code shows the error.










    share|improve this question



























      0












      0








      0








      i am posting a new question to bugfix for my code.



          if [ -f /etc/centos-release ]; then
      OS="CentOs"
      VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
      VER=${VERFULL:0:1} # return 6 or 7
      elif [ -f /etc/lsb-release ]; then
      OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
      VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
      elif [ -f /etc/os-release ]; then
      OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')
      VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')
      else
      OS=$(uname -s)
      VER=$(uname -r)
      fi


      Here elif [ -f /etc/lsb-release ]; then code shows the error.










      share|improve this question
















      i am posting a new question to bugfix for my code.



          if [ -f /etc/centos-release ]; then
      OS="CentOs"
      VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
      VER=${VERFULL:0:1} # return 6 or 7
      elif [ -f /etc/lsb-release ]; then
      OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
      VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
      elif [ -f /etc/os-release ]; then
      OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')
      VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')
      else
      OS=$(uname -s)
      VER=$(uname -r)
      fi


      Here elif [ -f /etc/lsb-release ]; then code shows the error.







      shell-script






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 26 at 16:10









      Rui F Ribeiro

      42.8k1486147




      42.8k1486147










      asked Jun 16 '18 at 18:01









      KvvaradhaKvvaradha

      1063




      1063






















          3 Answers
          3






          active

          oldest

          votes


















          2














          If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then on the first line.



          You could view your script with cat -A to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A will show line-feed characters as $ at the end of each line, control characters with the ^ prefix, and nonprintable characters with the 8th bit set with the M- prefix. For example, TAB characters will show up as ^I.



          The cat -A output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.






          share|improve this answer



















          • 1





            likely a carriage return (^M) preventing the shell from recognizing the then at end of line

            – ilkkachu
            Jun 16 '18 at 19:03











          • That is one of the possibilities, yes; another common nuisance is Alt-space. cat -A should catch them all.

            – telcoM
            Jun 16 '18 at 19:27











          • Tried it. Still the same issue comes.

            – Kvvaradha
            Jun 17 '18 at 3:50



















          0














          That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.



          $ cat -A x1
          #!/bin/bash$
          if [ -f /etc/centos-release ]; then$
          OS="CentOs"$
          VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
          VER=${VERFULL:0:1} # return 6 or 7$
          elif [ -f /etc/lsb-release ]; then$
          OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
          VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
          elif [ -f /etc/os-release ]; then$
          OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
          VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
          else$
          OS=$(uname -s)$
          VER=$(uname -r)$
          fi$
          $ ./x1
          $





          share|improve this answer
























          • I exactly used the same code in new . it results the same issue

            – Kvvaradha
            Jun 17 '18 at 3:51



















          0














          I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.






          share|improve this answer








          New contributor



          Lazor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















            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',
            autoActivateHeartbeat: false,
            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%2f450179%2fsyntax-error-elif-unexpected-expecting-then%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then on the first line.



            You could view your script with cat -A to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A will show line-feed characters as $ at the end of each line, control characters with the ^ prefix, and nonprintable characters with the 8th bit set with the M- prefix. For example, TAB characters will show up as ^I.



            The cat -A output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.






            share|improve this answer



















            • 1





              likely a carriage return (^M) preventing the shell from recognizing the then at end of line

              – ilkkachu
              Jun 16 '18 at 19:03











            • That is one of the possibilities, yes; another common nuisance is Alt-space. cat -A should catch them all.

              – telcoM
              Jun 16 '18 at 19:27











            • Tried it. Still the same issue comes.

              – Kvvaradha
              Jun 17 '18 at 3:50
















            2














            If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then on the first line.



            You could view your script with cat -A to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A will show line-feed characters as $ at the end of each line, control characters with the ^ prefix, and nonprintable characters with the 8th bit set with the M- prefix. For example, TAB characters will show up as ^I.



            The cat -A output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.






            share|improve this answer



















            • 1





              likely a carriage return (^M) preventing the shell from recognizing the then at end of line

              – ilkkachu
              Jun 16 '18 at 19:03











            • That is one of the possibilities, yes; another common nuisance is Alt-space. cat -A should catch them all.

              – telcoM
              Jun 16 '18 at 19:27











            • Tried it. Still the same issue comes.

              – Kvvaradha
              Jun 17 '18 at 3:50














            2












            2








            2







            If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then on the first line.



            You could view your script with cat -A to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A will show line-feed characters as $ at the end of each line, control characters with the ^ prefix, and nonprintable characters with the 8th bit set with the M- prefix. For example, TAB characters will show up as ^I.



            The cat -A output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.






            share|improve this answer













            If the shell reports that error on the 5th line of the script you posted, there must be some invisible error with the then on the first line.



            You could view your script with cat -A to see if there are accidental ALT-space characters or other non-printable characters on the line. cat -A will show line-feed characters as $ at the end of each line, control characters with the ^ prefix, and nonprintable characters with the 8th bit set with the M- prefix. For example, TAB characters will show up as ^I.



            The cat -A output can look a bit messy, but it's a great way to ensure there aren't any non-printable characters where they should not be.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 16 '18 at 18:12









            telcoMtelcoM

            21.8k12554




            21.8k12554








            • 1





              likely a carriage return (^M) preventing the shell from recognizing the then at end of line

              – ilkkachu
              Jun 16 '18 at 19:03











            • That is one of the possibilities, yes; another common nuisance is Alt-space. cat -A should catch them all.

              – telcoM
              Jun 16 '18 at 19:27











            • Tried it. Still the same issue comes.

              – Kvvaradha
              Jun 17 '18 at 3:50














            • 1





              likely a carriage return (^M) preventing the shell from recognizing the then at end of line

              – ilkkachu
              Jun 16 '18 at 19:03











            • That is one of the possibilities, yes; another common nuisance is Alt-space. cat -A should catch them all.

              – telcoM
              Jun 16 '18 at 19:27











            • Tried it. Still the same issue comes.

              – Kvvaradha
              Jun 17 '18 at 3:50








            1




            1





            likely a carriage return (^M) preventing the shell from recognizing the then at end of line

            – ilkkachu
            Jun 16 '18 at 19:03





            likely a carriage return (^M) preventing the shell from recognizing the then at end of line

            – ilkkachu
            Jun 16 '18 at 19:03













            That is one of the possibilities, yes; another common nuisance is Alt-space. cat -A should catch them all.

            – telcoM
            Jun 16 '18 at 19:27





            That is one of the possibilities, yes; another common nuisance is Alt-space. cat -A should catch them all.

            – telcoM
            Jun 16 '18 at 19:27













            Tried it. Still the same issue comes.

            – Kvvaradha
            Jun 17 '18 at 3:50





            Tried it. Still the same issue comes.

            – Kvvaradha
            Jun 17 '18 at 3:50













            0














            That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.



            $ cat -A x1
            #!/bin/bash$
            if [ -f /etc/centos-release ]; then$
            OS="CentOs"$
            VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
            VER=${VERFULL:0:1} # return 6 or 7$
            elif [ -f /etc/lsb-release ]; then$
            OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
            VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
            elif [ -f /etc/os-release ]; then$
            OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
            VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
            else$
            OS=$(uname -s)$
            VER=$(uname -r)$
            fi$
            $ ./x1
            $





            share|improve this answer
























            • I exactly used the same code in new . it results the same issue

              – Kvvaradha
              Jun 17 '18 at 3:51
















            0














            That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.



            $ cat -A x1
            #!/bin/bash$
            if [ -f /etc/centos-release ]; then$
            OS="CentOs"$
            VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
            VER=${VERFULL:0:1} # return 6 or 7$
            elif [ -f /etc/lsb-release ]; then$
            OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
            VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
            elif [ -f /etc/os-release ]; then$
            OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
            VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
            else$
            OS=$(uname -s)$
            VER=$(uname -r)$
            fi$
            $ ./x1
            $





            share|improve this answer
























            • I exactly used the same code in new . it results the same issue

              – Kvvaradha
              Jun 17 '18 at 3:51














            0












            0








            0







            That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.



            $ cat -A x1
            #!/bin/bash$
            if [ -f /etc/centos-release ]; then$
            OS="CentOs"$
            VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
            VER=${VERFULL:0:1} # return 6 or 7$
            elif [ -f /etc/lsb-release ]; then$
            OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
            VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
            elif [ -f /etc/os-release ]; then$
            OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
            VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
            else$
            OS=$(uname -s)$
            VER=$(uname -r)$
            fi$
            $ ./x1
            $





            share|improve this answer













            That script snippet runs fine for me. As @telecoM notes, is likely some odd characters within your script.



            $ cat -A x1
            #!/bin/bash$
            if [ -f /etc/centos-release ]; then$
            OS="CentOs"$
            VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)$
            VER=${VERFULL:0:1} # return 6 or 7$
            elif [ -f /etc/lsb-release ]; then$
            OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')$
            VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')$
            elif [ -f /etc/os-release ]; then$
            OS=$(grep -w ID /etc/os-release | sed 's/^.*=//')$
            VER=$(grep VERSION_ID /etc/os-release | sed 's/^.*"(.*)"/1/')$
            else$
            OS=$(uname -s)$
            VER=$(uname -r)$
            fi$
            $ ./x1
            $






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 16 '18 at 18:14









            stevesteve

            14.5k22854




            14.5k22854













            • I exactly used the same code in new . it results the same issue

              – Kvvaradha
              Jun 17 '18 at 3:51



















            • I exactly used the same code in new . it results the same issue

              – Kvvaradha
              Jun 17 '18 at 3:51

















            I exactly used the same code in new . it results the same issue

            – Kvvaradha
            Jun 17 '18 at 3:51





            I exactly used the same code in new . it results the same issue

            – Kvvaradha
            Jun 17 '18 at 3:51











            0














            I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.






            share|improve this answer








            New contributor



            Lazor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.
























              0














              I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.






              share|improve this answer








              New contributor



              Lazor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















                0












                0








                0







                I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.






                share|improve this answer








                New contributor



                Lazor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                I ran into this type of problem. The solution for me was to run dos2unix on the file. Everything was fine afterward.







                share|improve this answer








                New contributor



                Lazor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.








                share|improve this answer



                share|improve this answer






                New contributor



                Lazor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.








                answered 20 mins ago









                LazorLazor

                1011




                1011




                New contributor



                Lazor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.




                New contributor




                Lazor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.
































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f450179%2fsyntax-error-elif-unexpected-expecting-then%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

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...