msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

20 May 2007 Root Check

Posted by

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

Tags:

Comments are closed.