How to check not starts with condition in if statement?

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











up vote
0
down vote

favorite












I want to check the condition like below. Line should not starts with #
symbol:



if[ ! ["$Line" == "#*"] ]; then


But this is not working.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I want to check the condition like below. Line should not starts with #
    symbol:



    if[ ! ["$Line" == "#*"] ]; then


    But this is not working.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want to check the condition like below. Line should not starts with #
      symbol:



      if[ ! ["$Line" == "#*"] ]; then


      But this is not working.










      share|improve this question















      I want to check the condition like below. Line should not starts with #
      symbol:



      if[ ! ["$Line" == "#*"] ]; then


      But this is not working.







      shell-script






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 31 at 2:28









      Steven Penny

      2,31921635




      2,31921635










      asked Jun 30 '16 at 4:37









      Rajagopalarao

      32




      32




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.



          You can negate equality operator instead:



          if [[ "$LINE" != #* ]]; then echo yes; fi


          Take also closer look to spaces surrounding brackets.






          share|improve this answer





























            up vote
            0
            down vote













            Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.



            case $line in
            "#"*) echo no
            esac


            The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.



            If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in



            case $line in
            "#"*) echo no ;;
            *) echo yes
            esac


            ... and the code for a pattern may be empty:



            case $line in
            "#"*) ;;
            *) echo yes
            esac


            The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:



            if [[ $line != "#"* ]]; then
            echo yes
            else
            echo no
            fi


            In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:



            if ! [[ $line =~ ^# ]]; then
            echo yes
            else
            echo no
            fi


            or



            if [[ $line =~ ^[^#] ]]; then
            echo yes
            else
            echo no
            fi


            If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:



            awk '/^[^#]/ print yes ' <inputfile


            Related:



            • Why is using a shell loop to process text considered bad practice?





            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%2f293016%2fhow-to-check-not-starts-with-condition-in-if-statement%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
              1
              down vote













              There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.



              You can negate equality operator instead:



              if [[ "$LINE" != #* ]]; then echo yes; fi


              Take also closer look to spaces surrounding brackets.






              share|improve this answer


























                up vote
                1
                down vote













                There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.



                You can negate equality operator instead:



                if [[ "$LINE" != #* ]]; then echo yes; fi


                Take also closer look to spaces surrounding brackets.






                share|improve this answer
























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.



                  You can negate equality operator instead:



                  if [[ "$LINE" != #* ]]; then echo yes; fi


                  Take also closer look to spaces surrounding brackets.






                  share|improve this answer














                  There are many problems in your snippet, but basically the syntax [![...]] is not valid, in the bash (and many other shells) [[ is a single command, which cannot be split by any other character.



                  You can negate equality operator instead:



                  if [[ "$LINE" != #* ]]; then echo yes; fi


                  Take also closer look to spaces surrounding brackets.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 30 '16 at 5:59

























                  answered Jun 30 '16 at 5:53









                  jimmij

                  29.3k867101




                  29.3k867101






















                      up vote
                      0
                      down vote













                      Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.



                      case $line in
                      "#"*) echo no
                      esac


                      The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.



                      If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in



                      case $line in
                      "#"*) echo no ;;
                      *) echo yes
                      esac


                      ... and the code for a pattern may be empty:



                      case $line in
                      "#"*) ;;
                      *) echo yes
                      esac


                      The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:



                      if [[ $line != "#"* ]]; then
                      echo yes
                      else
                      echo no
                      fi


                      In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:



                      if ! [[ $line =~ ^# ]]; then
                      echo yes
                      else
                      echo no
                      fi


                      or



                      if [[ $line =~ ^[^#] ]]; then
                      echo yes
                      else
                      echo no
                      fi


                      If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:



                      awk '/^[^#]/ print yes ' <inputfile


                      Related:



                      • Why is using a shell loop to process text considered bad practice?





                      share|improve this answer


























                        up vote
                        0
                        down vote













                        Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.



                        case $line in
                        "#"*) echo no
                        esac


                        The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.



                        If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in



                        case $line in
                        "#"*) echo no ;;
                        *) echo yes
                        esac


                        ... and the code for a pattern may be empty:



                        case $line in
                        "#"*) ;;
                        *) echo yes
                        esac


                        The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:



                        if [[ $line != "#"* ]]; then
                        echo yes
                        else
                        echo no
                        fi


                        In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:



                        if ! [[ $line =~ ^# ]]; then
                        echo yes
                        else
                        echo no
                        fi


                        or



                        if [[ $line =~ ^[^#] ]]; then
                        echo yes
                        else
                        echo no
                        fi


                        If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:



                        awk '/^[^#]/ print yes ' <inputfile


                        Related:



                        • Why is using a shell loop to process text considered bad practice?





                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.



                          case $line in
                          "#"*) echo no
                          esac


                          The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.



                          If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in



                          case $line in
                          "#"*) echo no ;;
                          *) echo yes
                          esac


                          ... and the code for a pattern may be empty:



                          case $line in
                          "#"*) ;;
                          *) echo yes
                          esac


                          The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:



                          if [[ $line != "#"* ]]; then
                          echo yes
                          else
                          echo no
                          fi


                          In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:



                          if ! [[ $line =~ ^# ]]; then
                          echo yes
                          else
                          echo no
                          fi


                          or



                          if [[ $line =~ ^[^#] ]]; then
                          echo yes
                          else
                          echo no
                          fi


                          If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:



                          awk '/^[^#]/ print yes ' <inputfile


                          Related:



                          • Why is using a shell loop to process text considered bad practice?





                          share|improve this answer














                          Assuming that you have a string in the variable line and you want to output the string yes if it doesn't start with the character #. In the examples below, I will also output no when the condition is not met.



                          case $line in
                          "#"*) echo no
                          esac


                          The case statement takes a variable and then any number of (globbing) patterns, and executes the code for the pattern that matches the value of the variable. In this case we try to match the pattern "#"* (the # has to be quoted as to not be taken as introducing a comment), and if it matches, an echo statement is executed.



                          If there are more patterns, then the code for all but the last pattern has to be terminated by ;;, as in



                          case $line in
                          "#"*) echo no ;;
                          *) echo yes
                          esac


                          ... and the code for a pattern may be empty:



                          case $line in
                          "#"*) ;;
                          *) echo yes
                          esac


                          The bash shell also does pattern matching with globs in [[ ... ]] with the == operator:



                          if [[ $line != "#"* ]]; then
                          echo yes
                          else
                          echo no
                          fi


                          In bash, you may also use regular expression matching with the =~ operator within [[ ... ]]:



                          if ! [[ $line =~ ^# ]]; then
                          echo yes
                          else
                          echo no
                          fi


                          or



                          if [[ $line =~ ^[^#] ]]; then
                          echo yes
                          else
                          echo no
                          fi


                          If you're paring a file line by line, then the shell is not the right tool for that job. Instead you may want to use something like awk:



                          awk '/^[^#]/ print yes ' <inputfile


                          Related:



                          • Why is using a shell loop to process text considered bad practice?






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Aug 31 at 7:02

























                          answered Aug 31 at 6:54









                          Kusalananda

                          107k14209331




                          107k14209331



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f293016%2fhow-to-check-not-starts-with-condition-in-if-statement%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              Peggy Mitchell

                              Palaiologos

                              The Forum (Inglewood, California)