Get all characters before first instance of another char

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











up vote
0
down vote

favorite












Say I have



npmv="3.4.5";


what is the simplest way to get all the characters before the first dot? In this case that would be "3"?







share|improve this question























    up vote
    0
    down vote

    favorite












    Say I have



    npmv="3.4.5";


    what is the simplest way to get all the characters before the first dot? In this case that would be "3"?







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Say I have



      npmv="3.4.5";


      what is the simplest way to get all the characters before the first dot? In this case that would be "3"?







      share|improve this question











      Say I have



      npmv="3.4.5";


      what is the simplest way to get all the characters before the first dot? In this case that would be "3"?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 22 at 7:32









      Alexander Mills

      1,848929




      1,848929




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          npmv="3.4.5"
          major=$npmv%%.*

          printf 'The major version number is %sn' "$major"


          The parameter substitution $variable%%pattern will remove the longest suffix string matching pattern from the value of $variable. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.



          The same thing but with a single % would remove only the final .5 of the string in the example (the shortest matching suffix pattern). For prefix strings, use # instead of %.



          See also the section on parameter expansions in the POSIX standard, and your shell's manual.






          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%2f451238%2fget-all-characters-before-first-instance-of-another-char%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
            3
            down vote



            accepted










            npmv="3.4.5"
            major=$npmv%%.*

            printf 'The major version number is %sn' "$major"


            The parameter substitution $variable%%pattern will remove the longest suffix string matching pattern from the value of $variable. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.



            The same thing but with a single % would remove only the final .5 of the string in the example (the shortest matching suffix pattern). For prefix strings, use # instead of %.



            See also the section on parameter expansions in the POSIX standard, and your shell's manual.






            share|improve this answer



























              up vote
              3
              down vote



              accepted










              npmv="3.4.5"
              major=$npmv%%.*

              printf 'The major version number is %sn' "$major"


              The parameter substitution $variable%%pattern will remove the longest suffix string matching pattern from the value of $variable. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.



              The same thing but with a single % would remove only the final .5 of the string in the example (the shortest matching suffix pattern). For prefix strings, use # instead of %.



              See also the section on parameter expansions in the POSIX standard, and your shell's manual.






              share|improve this answer

























                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                npmv="3.4.5"
                major=$npmv%%.*

                printf 'The major version number is %sn' "$major"


                The parameter substitution $variable%%pattern will remove the longest suffix string matching pattern from the value of $variable. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.



                The same thing but with a single % would remove only the final .5 of the string in the example (the shortest matching suffix pattern). For prefix strings, use # instead of %.



                See also the section on parameter expansions in the POSIX standard, and your shell's manual.






                share|improve this answer















                npmv="3.4.5"
                major=$npmv%%.*

                printf 'The major version number is %sn' "$major"


                The parameter substitution $variable%%pattern will remove the longest suffix string matching pattern from the value of $variable. The pattern is treated as a filename globbing pattern, not a regular expression. This is a standard parameter substitution that will work in all POSIX shells.



                The same thing but with a single % would remove only the final .5 of the string in the example (the shortest matching suffix pattern). For prefix strings, use # instead of %.



                See also the section on parameter expansions in the POSIX standard, and your shell's manual.







                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jun 22 at 7:45


























                answered Jun 22 at 7:39









                Kusalananda

                101k13199312




                101k13199312






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451238%2fget-all-characters-before-first-instance-of-another-char%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay