Snippet to check root privileges

Snippet to use in your scripts to execute them only if you have root privileges.
犀利士

 bash | 
 
 copy code |
?

1
if [ $UID -ne 0 ]; then  
2
echo "Superuser privileges are required to run this script." 
3
echo "e.g. "sudo $0"" 
4
exit 1 fi