How to pipe a 'yes' or 'y' into a program while invoked with 'sudo' in bash?

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











up vote
4
down vote

favorite
1












How to pipe a Y or yes to a program while invoking with sudo?



We can type like this



yes | command
yes | yum update


How to pipe the y from yes into a program via sudo like the following?



yes| sudo command


The y from yes is be passed into command and should go into sudo and sudo shall ask for password normally. How can I do this?







share|improve this question


























    up vote
    4
    down vote

    favorite
    1












    How to pipe a Y or yes to a program while invoking with sudo?



    We can type like this



    yes | command
    yes | yum update


    How to pipe the y from yes into a program via sudo like the following?



    yes| sudo command


    The y from yes is be passed into command and should go into sudo and sudo shall ask for password normally. How can I do this?







    share|improve this question
























      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      How to pipe a Y or yes to a program while invoking with sudo?



      We can type like this



      yes | command
      yes | yum update


      How to pipe the y from yes into a program via sudo like the following?



      yes| sudo command


      The y from yes is be passed into command and should go into sudo and sudo shall ask for password normally. How can I do this?







      share|improve this question














      How to pipe a Y or yes to a program while invoking with sudo?



      We can type like this



      yes | command
      yes | yum update


      How to pipe the y from yes into a program via sudo like the following?



      yes| sudo command


      The y from yes is be passed into command and should go into sudo and sudo shall ask for password normally. How can I do this?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 15 '17 at 21:52

























      asked Dec 15 '17 at 13:41









      Abhik Bose

      1,5341217




      1,5341217




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          10
          down vote



          accepted










          sudo reads the password from the terminal directly, not from its standard input, unless the -S option is used. Thus



          yes | sudo command


          should prompt for the password (if necessary), without reading from yes, then run command as root with its standard input fed from yes’s standard output.



          If that doesn’t work, you can run the whole pipeline under sudo using something like



          sudo sh -c "yes | command"





          share|improve this answer






















          • yes | sudo command not passing y to command although sudo is asking for password. sudo sh -c "yes | command" is working fine. But is there a way to do the same without invoking another child shell explicitly?
            – Abhik Bose
            Dec 15 '17 at 13:50







          • 1




            If your pipe doesn’t survive sudo (yes | sudo command), then you need something else to set a pipe up for you; sudo itself can’t do that, so you need a subshell to do it for you (sudo sh -c "yes | command").
            – Stephen Kitt
            Dec 15 '17 at 14:18






          • 1




            Is there more than one sudo implementation?
            – Stéphane Chazelas
            Dec 15 '17 at 15:59










          • @Stéphane good point, there probably is just sudo.ws.
            – Stephen Kitt
            Dec 15 '17 at 16:03










          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%2f411062%2fhow-to-pipe-a-yes-or-y-into-a-program-while-invoked-with-sudo-in-bash%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
          10
          down vote



          accepted










          sudo reads the password from the terminal directly, not from its standard input, unless the -S option is used. Thus



          yes | sudo command


          should prompt for the password (if necessary), without reading from yes, then run command as root with its standard input fed from yes’s standard output.



          If that doesn’t work, you can run the whole pipeline under sudo using something like



          sudo sh -c "yes | command"





          share|improve this answer






















          • yes | sudo command not passing y to command although sudo is asking for password. sudo sh -c "yes | command" is working fine. But is there a way to do the same without invoking another child shell explicitly?
            – Abhik Bose
            Dec 15 '17 at 13:50







          • 1




            If your pipe doesn’t survive sudo (yes | sudo command), then you need something else to set a pipe up for you; sudo itself can’t do that, so you need a subshell to do it for you (sudo sh -c "yes | command").
            – Stephen Kitt
            Dec 15 '17 at 14:18






          • 1




            Is there more than one sudo implementation?
            – Stéphane Chazelas
            Dec 15 '17 at 15:59










          • @Stéphane good point, there probably is just sudo.ws.
            – Stephen Kitt
            Dec 15 '17 at 16:03














          up vote
          10
          down vote



          accepted










          sudo reads the password from the terminal directly, not from its standard input, unless the -S option is used. Thus



          yes | sudo command


          should prompt for the password (if necessary), without reading from yes, then run command as root with its standard input fed from yes’s standard output.



          If that doesn’t work, you can run the whole pipeline under sudo using something like



          sudo sh -c "yes | command"





          share|improve this answer






















          • yes | sudo command not passing y to command although sudo is asking for password. sudo sh -c "yes | command" is working fine. But is there a way to do the same without invoking another child shell explicitly?
            – Abhik Bose
            Dec 15 '17 at 13:50







          • 1




            If your pipe doesn’t survive sudo (yes | sudo command), then you need something else to set a pipe up for you; sudo itself can’t do that, so you need a subshell to do it for you (sudo sh -c "yes | command").
            – Stephen Kitt
            Dec 15 '17 at 14:18






          • 1




            Is there more than one sudo implementation?
            – Stéphane Chazelas
            Dec 15 '17 at 15:59










          • @Stéphane good point, there probably is just sudo.ws.
            – Stephen Kitt
            Dec 15 '17 at 16:03












          up vote
          10
          down vote



          accepted







          up vote
          10
          down vote



          accepted






          sudo reads the password from the terminal directly, not from its standard input, unless the -S option is used. Thus



          yes | sudo command


          should prompt for the password (if necessary), without reading from yes, then run command as root with its standard input fed from yes’s standard output.



          If that doesn’t work, you can run the whole pipeline under sudo using something like



          sudo sh -c "yes | command"





          share|improve this answer














          sudo reads the password from the terminal directly, not from its standard input, unless the -S option is used. Thus



          yes | sudo command


          should prompt for the password (if necessary), without reading from yes, then run command as root with its standard input fed from yes’s standard output.



          If that doesn’t work, you can run the whole pipeline under sudo using something like



          sudo sh -c "yes | command"






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 15 '17 at 17:25

























          answered Dec 15 '17 at 13:46









          Stephen Kitt

          143k22309372




          143k22309372











          • yes | sudo command not passing y to command although sudo is asking for password. sudo sh -c "yes | command" is working fine. But is there a way to do the same without invoking another child shell explicitly?
            – Abhik Bose
            Dec 15 '17 at 13:50







          • 1




            If your pipe doesn’t survive sudo (yes | sudo command), then you need something else to set a pipe up for you; sudo itself can’t do that, so you need a subshell to do it for you (sudo sh -c "yes | command").
            – Stephen Kitt
            Dec 15 '17 at 14:18






          • 1




            Is there more than one sudo implementation?
            – Stéphane Chazelas
            Dec 15 '17 at 15:59










          • @Stéphane good point, there probably is just sudo.ws.
            – Stephen Kitt
            Dec 15 '17 at 16:03
















          • yes | sudo command not passing y to command although sudo is asking for password. sudo sh -c "yes | command" is working fine. But is there a way to do the same without invoking another child shell explicitly?
            – Abhik Bose
            Dec 15 '17 at 13:50







          • 1




            If your pipe doesn’t survive sudo (yes | sudo command), then you need something else to set a pipe up for you; sudo itself can’t do that, so you need a subshell to do it for you (sudo sh -c "yes | command").
            – Stephen Kitt
            Dec 15 '17 at 14:18






          • 1




            Is there more than one sudo implementation?
            – Stéphane Chazelas
            Dec 15 '17 at 15:59










          • @Stéphane good point, there probably is just sudo.ws.
            – Stephen Kitt
            Dec 15 '17 at 16:03















          yes | sudo command not passing y to command although sudo is asking for password. sudo sh -c "yes | command" is working fine. But is there a way to do the same without invoking another child shell explicitly?
          – Abhik Bose
          Dec 15 '17 at 13:50





          yes | sudo command not passing y to command although sudo is asking for password. sudo sh -c "yes | command" is working fine. But is there a way to do the same without invoking another child shell explicitly?
          – Abhik Bose
          Dec 15 '17 at 13:50





          1




          1




          If your pipe doesn’t survive sudo (yes | sudo command), then you need something else to set a pipe up for you; sudo itself can’t do that, so you need a subshell to do it for you (sudo sh -c "yes | command").
          – Stephen Kitt
          Dec 15 '17 at 14:18




          If your pipe doesn’t survive sudo (yes | sudo command), then you need something else to set a pipe up for you; sudo itself can’t do that, so you need a subshell to do it for you (sudo sh -c "yes | command").
          – Stephen Kitt
          Dec 15 '17 at 14:18




          1




          1




          Is there more than one sudo implementation?
          – Stéphane Chazelas
          Dec 15 '17 at 15:59




          Is there more than one sudo implementation?
          – Stéphane Chazelas
          Dec 15 '17 at 15:59












          @Stéphane good point, there probably is just sudo.ws.
          – Stephen Kitt
          Dec 15 '17 at 16:03




          @Stéphane good point, there probably is just sudo.ws.
          – Stephen Kitt
          Dec 15 '17 at 16:03












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f411062%2fhow-to-pipe-a-yes-or-y-into-a-program-while-invoked-with-sudo-in-bash%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?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?