4
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?
10
sudo reads the password from the terminal directly, not from its standard input, unless the -S option is used. Thusyes | 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 likesudo sh -c "yes | command"
沒有留言:
張貼留言