Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Why sudo -i command is not setting the TERM, PATH, HOME, SHELL, LOGNAME, USER and USERNAME on my fresh Ubuntu 12.04.1 LTS as decribed in the manual?

# sudo -u johnny -i echo $HOME && echo $USER

Using -H is not setting $HOME either. And my user does exist with a home :

# cat /etc/passwd

Update : Why am I having this issue? Because I am trying to create an ubuntu upstart job for multiple unicorn applications & I am using user installation of RVM + Bundle : without $HOME being properly evaluated, RVM do not find ~/.rvm.

share|improve this question
I'd guess that sudo -E -u johnny echo $HOME && sudo -E -u johnny echo $USER would've worked for you. – krowe Sep 26 '13 at 17:04

2 Answers 2

Not really an answer, but have you tried this:

$ cat /home/foo/
echo $USER
echo $HOME

$ chmod +x /home/foo/
$ sudo -u johnny -i "/home/foo/"

While running this:

$ sudo -u johnny -i echo $USER && echo $HOME

Looks like your $USER is being evaluated in the command line, while the command is executed as the initial user.

share|improve this answer
Thanks for the hints, $USER is indeed being evaluated from the first command call and this is where my idea completely fail. I found a way to hack around this using new shell & escaping the variable from the first command call like this : sudo -u johnny -i /bin/sh -c "echo \$HOME". – jpdoyle Sep 23 '12 at 2:36

In your example the variables ($HOME, $USER, ...) are interpreted before the sudo command is executed.

This, in contrast, should work as you'd expect it:

sudo -u johnny -i env | grep HOME
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.