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

Canonical Launches ARM Laptop Certification Program to Boost Ubuntu’s Next Generation of Mobile Computing
Canonical Launches ARM Laptop Certification Program to Boost Ubuntu’s Next Generation of Mobile Computing
George Whittaker
Btrfs Snapshot Deletion Gets Faster as Developers Tackle One of the Filesystem’s Biggest Pain Points
Btrfs Snapshot Deletion Gets Faster as Developers Tackle One of the Filesystem’s Biggest Pain Points
George Whittaker
How Digital Software Is Powering Innovation in Modern Product Design
How Digital Software Is Powering Innovation in Modern Product Design
Will Jones
GNOME Files Supercharges Search with Faster Results, Smarter Filters, and Better File Discovery
GNOME Files Supercharges Search with Faster Results, Smarter Filters, and Better File Discovery
George Whittaker
NixOS 26.05 ‘Yarara’ Released with Systemd Initrd by Default and Major Infrastructure Updates
NixOS 26.05 ‘Yarara’ Released with Systemd Initrd by Default and Major Infrastructure Updates
George Whittaker
GNOME 51 Development Officially Begins as ‘A Coruña’ Cycle Gets Underway
GNOME 51 Development Officially Begins as ‘A Coruña’ Cycle Gets Underway
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
×