Skip to main content

Linux Journal

  • Topics+
    • Cloud
    • Containers
    • Desktop
    • Kernel
    • Mobile
    • Networking
    • Privacy
    • Programming
    • Security
    • Servers
    • SysAdmin
  • News
  • eBooks

Search

Enter the terms you wish to search for.
  • News
  • Popular
  • Recent
 

HOW-TOs

Check to see if a script was run as root

by Mitch Frazier
on April 16, 2008

If you need to make sure a script is run as root, add the following to the start of the script:

  if [[ $UID -ne 0 ]]; then
    echo "$0 must be run as root"
    exit 1
  fi

Mitch Frazier is an embedded systems programmer at Emerson Electric Co. Mitch has been a contributor to and a friend of Linux Journal since the early 2000s.

Load Disqus comments

Recent Articles

Azure Linux 4.0 Released: Microsoft Expands Its Enterprise Linux Platform Beyond the Cloud
Azure Linux 4.0 Released: Microsoft Expands Its Enterprise Linux Platform Beyond the Cloud
George Whittaker
KDE Plasma 6.7.1 Released with Stability Fixes, UI Improvements, and Better Wayland Reliability
KDE Plasma 6.7.1 Released with Stability Fixes, UI Improvements, and Better Wayland Reliability
George Whittaker
PorteuX 2.6 Released with Linux 6.19, TLP Support, and Smarter Hardware Optimization
PorteuX 2.6 Released with Linux 6.19, TLP Support, and Smarter Hardware Optimization
George Whittaker
CachyOS June 2026 ISO Released with Hyprland Noctalia, Faster Performance, and Smarter System Tools
CachyOS June 2026 ISO Released with Hyprland Noctalia, Faster Performance, and Smarter System Tools
George Whittaker
Git 2.55 Released with Faster Performance, Smarter Hooks, and Expanded Rust Integration
Git 2.55 Released with Faster Performance, Smarter Hooks, and Expanded Rust Integration
George Whittaker
Fedora Governance Changes Take Effect as Project Refines Leadership, Policy, and Contributor Oversight
Fedora Governance Changes Take Effect as Project Refines Leadership, Policy, and Contributor Oversight
George Whittaker
Connect With Us

Linux Journal, representing 25+ years of publication, is the original magazine of the global Open Source community.

© 2026 Slashdot Media, LLC. All rights reserved.
  • PRIVACY POLICY
  • TERMS OF SERVICE
  • ADVERTISE

Footer Menu Column 2

  • Masthead
  • Authors
  • Contact Us

Footer Menu Column 3

  • RSS Feeds
  • About Us
×