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
I think $SUDO_USER is valid.
#!/bin/bash echo $SUDO_USER whoami