I\'m writing a script that requires root level permissions, and I want to make it so that if the script is not run as root, it simply echoes \"Please run as root.\" and exit
A few answers have been given, but it appears that the best method is to use is:
id -u
This appears to be more reliable than the other methods, and it seems that it return an id of 0 even if the script is run through sudo.
sudo