Bash (Scripting) - Run a BASH script as root
by
Jeremy Canfield |
Updated: October 01 2023
| Bash (Scripting) articles
The following markup in a BASH script can be used to ensure that the script is being run as root. Credit goes to this post on Ask Ubuntu for this markup.
#!/bin/bash
if [[ $EUID -ne 0 ]];
then
echo "This script must be run as root"
exit 1
fi
Did you find this article helpful?
If so, consider buying me a coffee over at