Bash-check-if-root-user: Difference between revisions

From I Will Fear No Evil
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
Line 1: Line 1:
<metadesc>bash function to see if the user running the script is the root user or not</metadesc>
<metadesc>bash function to see if the user running the script is the root user or not</metadesc>
== function check if root ==
<pre>
<pre>
got_root() {
got_root() {

Latest revision as of 12:22, 3 September 2024

function check if root

got_root() {
if [ "$(id -u)" != "0" ]; then
  echo "Failure:  This script must be run as root or sudo used"; exit 2
else
  echo "Confirmed: running as root, or sudo used"
fi
}