Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Example command is as follows, run as a normal user

which python
/home/me/env/development/python 

because the PATH environment contains a path that points out to this instance of python (instead to point to /usr/bin/python).

I want to be able to run a python command with the SAME environment variable, so

sudo which python

which returns /usr/bin/python instead. Using the -E option gives the same result.

How can I run a python command with root-right, but with the environment variables preserved. I do not want to specify them all with the sudo command, and I guess to 'copy' only the PATH variables should be enough.

Question formulated in other words: How can I run a python command with sudo, which has the same PATH definition as I currently have as a normal user?

share|improve this question
1  
Does editing /etc/sudoers to unset the env_reset and maybe secure_path flags help? See man 5 sudoers and here. –  Michael Kjörling Jul 11 '13 at 9:43
    
I tried to include PATH in env_keep, but it did not change the outcome of the test –  Alex Jul 11 '13 at 10:56
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.