Skip to content

Instantly share code, notes, and snippets.

@frederikheld
Created May 8, 2023 22:49
Show Gist options
  • Save frederikheld/76199f69b482400426b6121ccc01defe to your computer and use it in GitHub Desktop.
Save frederikheld/76199f69b482400426b6121ccc01defe to your computer and use it in GitHub Desktop.
Make sure that script is being run as sudo
#!/bin/sh
if [ "$(id -u)" -ne 0 ]
then
echo "This scripts needs elevated privileges. Please run as sudo!"
echo "Correct usage:"
echo " $ sudo sh $(basename "$0")"
exit 1
fi
echo "Hello Sudo!"
@frederikheld
Copy link
Author

See this comment on why this might not be the best way to go: https://unix.stackexchange.com/a/353207/320012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment