Skip to content

Instantly share code, notes, and snippets.

@jimkil
Last active March 4, 2022 12:26
Show Gist options
  • Select an option

  • Save jimkil/779ca66f9d7c0fa22f678ded4344446c to your computer and use it in GitHub Desktop.

Select an option

Save jimkil/779ca66f9d7c0fa22f678ded4344446c to your computer and use it in GitHub Desktop.
[got-root] Function to check if script running as root. #function #bash #snippet
# bash function to check if user is root
function __got_root() {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 87 # non-root user exit code
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment