How to use multiple variable for input with read command?

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I am using GNU bash - version 4.2.10(1).
I want to read multiple variables using single read command in shell script. So i tried as below:



echo " Enter P N R : "
read P N R


but it's not working. It just ask for single value of P variable and returns prompt.
I googled it but don't found any solution.







share|improve this question

























    up vote
    1
    down vote

    favorite












    I am using GNU bash - version 4.2.10(1).
    I want to read multiple variables using single read command in shell script. So i tried as below:



    echo " Enter P N R : "
    read P N R


    but it's not working. It just ask for single value of P variable and returns prompt.
    I googled it but don't found any solution.







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am using GNU bash - version 4.2.10(1).
      I want to read multiple variables using single read command in shell script. So i tried as below:



      echo " Enter P N R : "
      read P N R


      but it's not working. It just ask for single value of P variable and returns prompt.
      I googled it but don't found any solution.







      share|improve this question











      I am using GNU bash - version 4.2.10(1).
      I want to read multiple variables using single read command in shell script. So i tried as below:



      echo " Enter P N R : "
      read P N R


      but it's not working. It just ask for single value of P variable and returns prompt.
      I googled it but don't found any solution.









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jul 30 at 7:26









      Dip

      183115




      183115




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).



          So, here the user must enter the values for P, N, R space or tab separated, like:



          value_for_P value_for_N value_for_R


          Or if the values can contain space:



          value for P value for N value for R


          (here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).



          If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:



          IFS= read -r P
          IFS= read -r N
          IFS= read -r R





          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%2f459267%2fhow-to-use-multiple-variable-for-input-with-read-command%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
            2
            down vote



            accepted










            read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).



            So, here the user must enter the values for P, N, R space or tab separated, like:



            value_for_P value_for_N value_for_R


            Or if the values can contain space:



            value for P value for N value for R


            (here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).



            If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:



            IFS= read -r P
            IFS= read -r N
            IFS= read -r R





            share|improve this answer



























              up vote
              2
              down vote



              accepted










              read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).



              So, here the user must enter the values for P, N, R space or tab separated, like:



              value_for_P value_for_N value_for_R


              Or if the values can contain space:



              value for P value for N value for R


              (here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).



              If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:



              IFS= read -r P
              IFS= read -r N
              IFS= read -r R





              share|improve this answer

























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).



                So, here the user must enter the values for P, N, R space or tab separated, like:



                value_for_P value_for_N value_for_R


                Or if the values can contain space:



                value for P value for N value for R


                (here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).



                If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:



                IFS= read -r P
                IFS= read -r N
                IFS= read -r R





                share|improve this answer















                read, without -r expects words on input to be delimited by the characters of the $IFS special parameter (by default SPC, TAB and NL, though as read reads only one line unless it ends in backslash, NL can't count) where backslash can be used to escape the separator or allow a line to be continued on the next physical line (backslash-newline sequences removed).



                So, here the user must enter the values for P, N, R space or tab separated, like:



                value_for_P value_for_N value_for_R


                Or if the values can contain space:



                value for P value for N value for R


                (here we didn't bother escaping the spaces for R as the rest of the line after the third word would end-up in R anyway; the user would still need to escape a trailing space though).



                If you want the user to enter the values on 3 lines, you'd need 3 read invocations. You'd then want -r to avoid the backslash processing and make IFS empty:



                IFS= read -r P
                IFS= read -r N
                IFS= read -r R






                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jul 30 at 8:47


























                answered Jul 30 at 7:36









                Stéphane Chazelas

                277k52511841




                277k52511841






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f459267%2fhow-to-use-multiple-variable-for-input-with-read-command%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)