What is the best way to check if a sudo user can in Bash?

Reading the sudo man page, I see that the -v flag can be used to check if the user has sudo privileges on his workstation. I have a piece of script that should check it out. If the user does not have sudo privileges, he displays:

Sorry, user tester may not run sudo on debian. 

How can I suppress this message and just execute the rest of the code?

+6
source share
1 answer

Try adding >/dev/null to your command. In case the message is printed in stderr, use 2>/dev/null or, as pointed out in the comments, use &>/dev/null to redirect both stdout and stderr to null.

+4
source

Source: https://habr.com/ru/post/1014926/


All Articles