On Friday 13 April 2007 16:13, McKown, John wrote:
>My mind is dying from sinuses. What I would like to do is change a
>subdirectory mentioned in the PATH variable with a different value. In
>particular, I have multiple JAVA releases installed. In /etc/profile, I
>set JAVA_HOME to the default directory and put JAVA_HOME/bin on the
>PATH. I would like to write a simple shell script which changes the
>current value of JAVA_HOME to a different value (easy) and change the
>JAVA_HOME/bin portion of the PATH to the "new" one, then invoke java.

The per-user symlink in ~/bin is a good idea, but to do per-process PATH
settings, you need to hack up the variable's value itself.  The easiest way
is to just prepend your new $JAVA_HOME/bin to the PATH, but that's
cheating. :-)  It sounds like what you want to do is replace any occurrances
of $JAVA_HOME in the PATH.  Sed(1) can, of course, do this:

#!/bin/bash
old_home=$JAVA_HOME
export JAVA_HOME=/new/java/path
if [ -n "$old_home" ]
then    PATH=$(echo "$PATH" | sed "[EMAIL PROTECTED](^\|:\)[EMAIL PROTECTED]@g")
else            PATH=$PATH:$JAVA_HOME/bin
fi

That assumes that if JAVA_HOME is unset, it is not in the PATH either, and it
preserves the order of directories within the PATH, which you probably want.
The strange-looking "\(^\|:\)" pattern matches either the beginning of the
string or a colon, which anchors the match of $old_home to the beginning of a
field within the PATH.  If you think you'll have pathnames with the "@"
delimiter in them, you should change it to some other character.

>What I really wish that I could do would be to "source" some file which
>would do the same so that the "default" java for that user would be
>changed until some over "java selection" script was sourced. Is this
>possible?

The above should do that, with a bit of modification to select the correct
value for the new JAVA_HOME.
        - MacK.
-----
Edmund R. MacKenty
Software Architect
Rocket Software, Inc.
Newton, MA USA

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

Reply via email to