Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to test if a user can sudo in Bash?

Reading the sudo man page, I see that the -v flag can be used to check if the user has sudo privileges in his workstation. I have a piece of script that needs to test it. If the user has not sudo privileges, it prints on screen:

Sorry, user tester may not run sudo on debian.

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

like image 216
XVirtusX Avatar asked Feb 13 '17 01:02

XVirtusX


1 Answers

Try to append >/dev/null in your command. In case the message is printed in stderr then use 2>/dev/null or as advised in comments use &>/dev/null to redirect both stdout and stderr to null.

like image 172
George Vasiliou Avatar answered Oct 24 '22 03:10

George Vasiliou