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

Sundar Nagarajan sundar.personal at gmail.com
Wed Apr 8 05:51:55 UTC 2009


kapil singh kushwah wrote:
> Hello ,
> 
> It is working fine. I guess you did it
> after login as a root.
> 
> I am getting :
> 
> common at common-laptop:~$ echo ${USER}
> common
> common at common-laptop:~$ sudo echo ${USER}
> common
> common at common-laptop:~$
> 
> 
> Thanks
> Kapil Singh Kushwah
> System/Network Administrator
> Hotwax Media Inc.

sudo echo ${USER} will cause top level shell to expand ${USER} - i.e. 
_BEFORE_ executing sudo. Hence you will see the same value with and 
without sudo






More information about the ubuntu-users mailing list