UID is an important environment variable that can be used to check whether the current script has been run as root user or regular user. For example:
if [ $UID -ne 0 ]; then
echo "Non root user. Please run as root."
else
echo "Root user"
fi
The UID for the root user is 0.
Source: Linux Shell Scripting Cookbook



