Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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
add comment

1 Answer

Not really an answer, but have you tried this:

$ cat /home/foo/test.sh
echo $USER
echo $HOME

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

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
add comment

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.