How to Run a Shell Script as Superuser
If you've ever tried to run a shell script as superuser in Linux by using the syntax sudo ./example-shell-script, you'll know that doesn't really work – the commands within the script are executed as you, not the superuser, so permissions issues can easily arise. Instead, if you want to run the script as superuser, this is how to do it:
- Create your script
- Change the permissions
chmod 755 example-shell-script
- Switch into superuser mode
sudo su -
- Run the script
- Log out of superuser mode
That's it. You're done. Pretty easy, right?
This post was published on Sunday, October 4th, 2009 by Robert James Reese in the following categories: Linux, VI Editor. Before using any of the code or other content in this post, you must read and agree to our Terms & Conditions.