bash – check that script is being executed by root

1
2
3
4
5
if [ $EUID -ne 0 ]
then
    /bin/echo $'\nThis script must be run as the root user!\n'
    exit
fi