Skip to content

Instantly share code, notes, and snippets.

@sellmerfud
Created September 6, 2013 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sellmerfud/6466066 to your computer and use it in GitHub Desktop.
Save sellmerfud/6466066 to your computer and use it in GitHub Desktop.
Automatically restart shell script as root using sudo.
# 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