linuxbashubuntuenvironment-variables

How do you give su the current user environment variables


I have a variable that is set through .bashrc.

In ~/.bashrc:

PROJ_HOME=~/Projects/stable

From a bash shell, I'd like to do something like this:

$ su -l kenneth -c 'echo $PROJ_HOME'

However, when I do this, the expected /home/kenneth/Projects/stable is not printed out.

Any ideas on how I can do this?


Solution

  • You need to export the variable. You may not need to use the -m option to su to preserve the environment.

    export PROJ_HOME=~/Projects/stable