How to check if a user is root

The following script will use the whoami command to see what user you are. If you are root, it’ll continue running the script. If not, it’ll exist the script telling you that you are not root and need to use sudo.


owner=$(who am i | awk '{print $1}')
if [ "$(whoami)" != 'root' ]; then
  	echo "You don't have permission to run $0 as non-root user. Use sudo"
		exit 1;