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

Karl F. Larsen klarsen1 at gmail.com
Tue Apr 7 11:51:48 UTC 2009


Arch Willingham wrote:
> 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
>   
    It is working FINE! When you use sudo, then your logged in as... 
root :-)


Karl


-- 

	Karl F. Larsen, AKA K5DI
	Linux User
	#450462   http://counter.li.org.
   PGP 4208 4D6E 595F 22B9 FF1C  ECB6 4A3C 2C54 FE23 53A7





More information about the ubuntu-users mailing list