Bugzilla – Bug 403
Sudo initial login feature taints cwd
Last modified: 2010-05-07 13:06:49 MDT
At first I thought this was something to do with someone overriding the shell builtins, but below I use "builtin" to force use of shell builtin. This prints "/" as expected: ~# sudo bash -c "builtin cd / && builtin pwd" / This should print "/", but doesn't: ~# sudo -i bash -c "builtin cd / && builtin pwd" /root This also prints "/", and works if I run any command other than "cd" as the first command: ~# sudo -i bash -c "builtin pwd && builtin cd / && builtin pwd" / This happens both on Ubuntu Linux 9.10 and Mac OS X, both running sudo v1.7.0
Sudo's -i flag changes the cwd to the target user's home directory, which appears to match the behavior you are seeing.