Check root at start of script

Some scripts need to be run as root and you may want to check at the start of that script that it is running as root. This can be done by checking the environment variable $EUID. This variable will hold the value 0 if it’s being run as root.

if [ "$EUID" -ne 0 ];then
    echo "Please run this script as root"
    exit 1