Run a BASH script as root

Home > Search
  by

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments