Root Check
Sometime it is useful to determine if a script is being run as root or not. A simple check can be performed at the start of a script before anything important is done. The bit of code below will do this.
# Check the script is being run by root if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" exit 1 fi