#!/bin/bash isRoot() { if [ "$UID" -ne 0 ] return 1 else return 0 fi } isRoot if ["$?" -ne 0 ] then echo "Must be root to run this script" exit 1 else echo "welcome root user" #do something fi
#!/bin/bash isRoot() { if [ "$UID" -ne 0 ] return 1 else return 0 fi } isRoot if ["$?" -ne 0 ] then echo "Must be root to run this script" exit 1 else echo "welcome root user" #do something fi