How to return user name in a script even if run by SUDO?

Arch Willingham arch at tuparks.com
Tue Apr 7 00:57:58 UTC 2009


How do I return the name of the user in a script even if it is fired off by SUDO? In other words, if my script has these two lines:

echo ${USERNAME}
echo ${USER}

If I run it normally when logged in a user named wareagle, it prints out:


wareagle
wareagle

But if I run it via sudo, it prints out:

root
root

I need to be able to know the name of the currently logged in user even if the script is run by sudo?

Thanks!

Arch



More information about the ubuntu-users mailing list