If I create the script /root/bin/whoami.sh containing:
/root/bin/whoami.sh
#!/bin/bash whoami
and this script is called by a user with a properly
Here is how to get the username of the person who called the script no matter if sudo or not:
if [ $SUDO_USER ]; then user=$SUDO_USER; else user=`whoami`; fi
or a shorter version
[ $SUDO_USER ] && user=$SUDO_USER || user=`whoami`