Pergunta

I have a need to set environment variables JAVA_HOME, CATALINA_HOME, PATH, and the like. I thought it would be a good idea to set these in a shared file, ~/.setenv, then call it in my ~/.profile:

... code ...

/home/myusername/.setenv

When I log in I see the echos print my JAVA_HOME variable and it is set correctly, but when I then do echo $JAVA_HOME manually it prints nothing.

Why isn't my .setenv script setting my variables?

Here is my .setenv file:

export JAVA_HOME=/usr/local/jdk1.6.0_45
export PATH=$PATH:$JAVA_HOME/bin
export CATALINA_HOME=/var/lib/apache-tomcat-6.0.37
export CATALINA_BASE=/var/lib/apache-tomcat-6.0.37

whoami

echo "JAVA_HOME set to $JAVA_HOME"
echo "CATALINA_HOME set to $CATALINA_HOME"
echo "You can change this in /home/myusername/.setenv"

Output when logging in:

Welcome to Ubuntu 13.04 (GNU/Linux 3.8.0-19-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

Last login: Thu Jun 13 16:11:21 2013 from 192.168.1.200
o#: command not found
myusername
JAVA_HOME set to /usr/local/jdk1.6.0_45
CATALINA_HOME set to /var/lib/apache-tomcat-6.0.37
You can change this in /home/myusername/.setenv
Foi útil?

Solução

You need to source the .setenv script so the variable assignments are done in the current shell rather than in a sub-shell. Variable assignments in a sub-shell have no effect on the parent shell.

. /home/myusername/.setenv
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top