Arduino (1) Brainf**k (1) Bugs (3) C (1) HTML (1) Install (3) Linux (27) Maths (1) Python (12) Raspberry Pi (4)

Wednesday, 22 February 2017

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