Return to Snippet

Revision: 94016
at January 20, 2024 18:18 by deanhouseholder


Updated URL

                                

Updated Code
#!/bin/bash
# Test if user is root

if [ $UID -ne 0 ]; then
  echo "ERROR: $0 must be run as root"
  exit 1
fi

Revision: 63203
at April 16, 2013 16:35 by deanhouseholder


Initial Code
#!/bin/bash
#Test if user is root

if [ "$(id -u 2>/dev/null)" != "0" ]; then
  echo "ERROR: $0 must be run as root" >&2
  exit 1
fi

Initial URL

                                

Initial Description
If you have a script that must be run as the root user, put this at the top:

Initial Title
Check to see if the user running the script is root

Initial Tags
Bash

Initial Language
Bash