Skip to content

Instantly share code, notes, and snippets.

@unabridgedxcrpt
Created January 24, 2019 22:32
Show Gist options
  • Save unabridgedxcrpt/a4f2ec5c79c9ede1fce371cae3eefa07 to your computer and use it in GitHub Desktop.
Save unabridgedxcrpt/a4f2ec5c79c9ede1fce371cae3eefa07 to your computer and use it in GitHub Desktop.
Check if launched as root (or sudo)
#!/bin/bash
if ((${EUID:-0} || "$(id -u)")); then
echo You are not root.
else
echo Hello, root.
fi
#Also:
# function amIRoot() {
# ! ((${EUID:-0} || "$(id -u)"))
# }
#
#from https://askubuntu.com/questions/15853/how-can-a-script-check-if-its-being-run-as-root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment