Created
September 6, 2013 16:10
-
-
Save sellmerfud/6466066 to your computer and use it in GitHub Desktop.
Automatically restart shell script as root using sudo.
This file contains 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
# Place this at the top of your script. | |
# The exit $? causes the shell to exit with the | |
# status of the script instance that is run with sudo. | |
if [[ $UID -ne 0 ]]; then | |
sudo -p "Restarting as root, password for %p: " bash $0 "$@" | |
exit $? | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment