sudo -E does not pass PYTHONPATH

Viewed 1838

I am trying to add a python path value to a different environment, as some script I run with another user needs it to be set.

Now, the weird thing is that when I run sudo -E, variables that I have in my env do pass on to the user I'm sudoing to- except that PYTHONPATH doesn't.

Running:

TESTVAR=testValue sudo -E bash -c 'echo $TESTVAR'

will print "testValue", but:

PYTHONPATH=testValue sudo -E bash -c 'echo $PYTHONPATH'

Won't print anything.

I'm trying to understand if there is anything special about specific variables, that sudo acts different with when passing them to a different environment.

Help will be much appreciated, Thanks.

3 Answers
sudo env "PYTHONPATH=$PYTHONPATH" bash -c 'echo $PYTHONPATH'

You need env to force the passing.

Related