if [[ $UID -ne 0 ]]
echo "$0 must be run as root"
UID is a variable that is set by the shell and holds the uid of the user that started the shell/script. 0 (zero) is (always) the root user.
The above code snippet checks to see if the user is root, if not it prints a message and exits.
Hope this helps.