0

I'm executing a command with sudo from bash script, and I'm wondering how to prevent sudo from displaying anything on the screen

echo "mypassword" |  sudo -S cp -u /scripts/.bashrc ~/ > /dev/null 2>&1

The result will be an output displaying: [sudo] password for username:

I want to hide that output..

now, before the first comment; This isn't the safest way, since you're entering your password into the script, but this is strictly internal servers.

2
  • I tried your script on Ubuntu 18.04 and it does not display messages as you expect. Commented Aug 19, 2021 at 7:45
  • Duplicate. Check this url. Commented Aug 19, 2021 at 8:36

1 Answer 1

2

Run sudo --help, we can get answer from the parameter list:

-p, --prompt=prompt           use the specified password prompt

Then,

echo "mypassword" | sudo -S --prompt="" cp -u /scripts/.bashrc ~/ > /dev/null 2>&1

may do the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.