3

I want this command to work silently,

echo "any_password" | sudo -S true

I tried redirecting the output of stdout and stderr to /dev/null. When I provide the correct password it works as expected, but when the password is incorrect I still see some error on the screen.

echo "incorrect_password" | sudo -S true > /dev/null 2>&1

gives,

Sorry, try again.

The output was only partially suppressed. Is there a way to suppress it completely?

  • 1
    Try echo foo | sudo -S true &> /dev/null However I can't reproduce it! – Ravexina Jul 6 at 15:33
  • 1
    I have tried it already, it doesn't work. Btw isn't this command the same as mine, just written differently(although mine is portable)? – Akash Karnatak Jul 6 at 15:38
  • Yes it is... as I said I can't reproduce it even with your command! try something like this: echo foo | sudo -S true > stdout 2> stderr check and see what is happening. what are the contents of these two file and what is going to be printed out on your terminal. – Ravexina Jul 6 at 15:41
  • 1
    By "I can't reproduce it" I mean that it's working perfectly fine for me... – Ravexina Jul 6 at 15:49
  • 1
    @AkashKarnatak same for me on Ubuntu 20.04. I'll keep you updated if I was able to find anything further. – Ravexina Jul 7 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.