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

Derek Broughton derek at pointerstop.ca
Tue Apr 7 01:56:59 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?

# sudo -i
# export

(I'm sure i could figure out how to do it in one line, but that does the
job)

That will show you that, in the sudo environment, a few extra variables are
available:
 declare -x SUDO_COMMAND="/bin/bash"
 declare -x SUDO_GID="1000"
 declare -x SUDO_UID="1000"
 declare -x SUDO_USER="derek"

hth
-- 
derek





More information about the ubuntu-users mailing list