sudo doesn't propagate $PWD

Asked by Mike Coleman

Binary package hint: sudo

The $PWD environment variable isn't being propogated/set by sudo. The command 'sudo printenv' doesn't mention PWD, for example. This is bad because it's a very standard env var, and many scripts expect it to exist.

sudo:
  Installed: 1.6.9p17-1ubuntu3
  Candidate: 1.6.9p17-1ubuntu3
  Version table:
 *** 1.6.9p17-1ubuntu3 0
        500 http://us.archive.ubuntu.com jaunty/main Packages
        100 /var/lib/dpkg/status

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu sudo Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Victor Vargas (kamus) said :
#1

Dear Mike, extract from https://help.ubuntu.com/community/Sudoers

Defaults env_reset , resets the terminal environment after switching to root. So, ie: all user set variables are removed. The second (root ALL=(ALL) ALL) just lets root do everything on any machine as any user. And the third (%admin ALL=(ALL) ALL) lets anybody in the admin group run anything as any user. Note that they will still require a password (thus giving you the normal behaviour you are so used
to), by defaults "/etc/sudoers".

Revision history for this message
Victor Vargas (kamus) said :
#2

This report was converted into a question because is not a effective bug.

Regards

Revision history for this message
Arnaud Soyez (weboide) said :
#3

If you just feel like passing a variable to the application, you can do something like this:

sudo PWD=/home/user printenv
or
sudo PWD=$(pwd) printenv

This stays safe and secure!

Can you help with this problem?

Provide an answer of your own, or ask Mike Coleman for more information if necessary.

To post a message you must log in.