Each user on a unix system is assigned a user id, or uid. You can see your uid by running 'id -u'. root will have a uid of zero.

So to check if the user running a script is root, you can simply check that id -u is equal to zero, like so:

if [ `id -u` == "0" ]; then
    # root
    # not root