Bash: Run entire shell script as root

less than 1 minute read

Placing sudo in the shebang line of a shell script runs the entire thing as root. Useful for scripts designed to, e.g. automate system upgrades or package manager wrappers — makes prepending everything with sudo no longer necessary.

#!/usr/bin/sudo /usr/bin/env bash

Via commandlinefu.com.

Comments