Posted By

deanhouseholder on 04/16/13


Shell Bash root

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Check to see if the user running the script is root

 / Published in: Bash

If you have a script that must be run as the root user, put this at the top:

  1. #!/bin/bash
  2. #Test if user is root
  4. if [ "$(id -u 2>/dev/null)" != "0" ]; then
  5. echo "ERROR: $0 must be run as root" >&2
  6. exit 1
  7. fi

Report this snippet  


RSS Icon Subscribe to comments
Posted By: Jacky888 on October 22, 2018

intex elyt e1 read more

You need to login to post a comment.