I am setting my JAVA_HOME
in my ~/.bashrc
file.
Now, I need to create a script that will change the JAVA_HOME
just for the current terminal, so that I can start an app that needs java 5.
I have created this script to do this task, but after finishing, I can see that JAVA_HOME is not updated
export JAVA_HOME=/usr/lib/jvm/java-5-oracle/
export PATH=$PATH:$JAVA_HOME
Here is the result
$ ./javaHome5.sh
$ echo $JAVA_HOME
/usr/lib/jvm/java-6-oracle/
I think that the reason this is not being applied, is that a script is executing in it's own terminal, so when the script ends, the current terminal will not be affected.
Currently, the only way I've found around this is:
- Edit my
~/.bashrc
and change the JAVA_HOME var - Run
source ~/.bashrc
to apply the changes in current terminal. Which again cannot be applied in a script, as thesource
command needs to be run in the current window.
Needless to say, this change applies to all new terminal windows, so I practically need to do this twice: One before starting my app, and one more time right after this, just to restore the environment vars to their default. That's not really convenient.
Do you have any ideas how can I change this var using a script?
source myscript.sh
works nicely, why didn't I think about this? I've also added an alias :alias j5='source ./myscript.sh'
– yannicuLar Jun 09 '16 at 09:57alias j5='source /absolute/path/to/myscript.sh'
so that you can callj5
from anywhere, independently of your current working directory. – Malte Skoruppa Jun 09 '16 at 10:09