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

From I Will Fear No Evil
Jump to navigation Jump to search
(Created page with "<pre> 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...")
 
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<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
}