Last active
March 4, 2022 12:26
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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