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

Multi tool use
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
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?
sudo pipe yes
add a comment |Â
up vote
4
down vote
favorite
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?
sudo pipe yes
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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?
sudo pipe yes
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?
sudo pipe yes
edited Dec 15 '17 at 21:52
asked Dec 15 '17 at 13:41


Abhik Bose
1,5341217
1,5341217
add a comment |Â
add a comment |Â
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"
yes | sudo command
not passingy
tocommand
althoughsudo
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 survivesudo
(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
add a comment |Â
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"
yes | sudo command
not passingy
tocommand
althoughsudo
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 survivesudo
(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
add a comment |Â
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"
yes | sudo command
not passingy
tocommand
althoughsudo
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 survivesudo
(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
add a comment |Â
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"
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"
edited Dec 15 '17 at 17:25
answered Dec 15 '17 at 13:46
Stephen Kitt
143k22309372
143k22309372
yes | sudo command
not passingy
tocommand
althoughsudo
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 survivesudo
(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
add a comment |Â
yes | sudo command
not passingy
tocommand
althoughsudo
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 survivesudo
(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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password