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
As far as I know the correct way to check it is:
if [ $(id -u) = "0" ]; then echo "You are root" else echo "You are NOT root" fi
See "Testing For Root" section here:
http://linuxcommand.org/lc3_wss0080.php