Help - Search - Members - Calendar
Full Version: Shell Programming, Why Won't Setting Path Stick.
Linuxhelp > Support > Technical Support
cjferris
Hello

I'm a Java programmer who's a newbe with RedHat (ver 9). To set up my environment I've written a very symple shell program to set the PATH and CLASSPATH. However, once the shell program has terminated none of the changes stick. For example PATH is the same as it was before running the setpath.sh program. What the heck is going on??? Please tell, I've done this a zillion times on the iSeries and pSeries and the setpath.sh changes stayed. Here is a copy of what I'm talking about. I'm sure its something simple and easy, but man, I'm lost. Thanks

listing of my shell program.

-rwxrwxrwx 1 ferris ferris 40 Oct 22 20:46 shell1.sh

[ferris@localhost java]$ head setpath.sh
#!/bin/sh
#
export JAVA_HOME=":/usr/java/j2sdk1.4.2_02/bin/"
PATH="$JAVA_HOME:$PATH"
echo $PATH

here is my before PATH

[ferris@localhost java]$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/ferris/bin

here I run the shell program and you can see the PATH has changed.

[ferris@localhost java]$ ./setpath.sh
:/usr/java/j2sdk1.4.2_02/bin/:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/ferris/bin

now here is the PATH afterwards. As you can see, it does change in the program does not stick, its the same.

[ferris@localhost java]$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/ferris/bin
[ferris@localhost java]$

Nothing sticks at this point, no PATH, no CLASSPATH not even JAVA_HOME.
blink.gif
hughesjr
You have to export any variables that you want to stay after the script is run...so the variable JAVA_HOME should be there after you are finished running the script ... do the command:

env | grep JAVA_HOME

and see if it stays...

Change the script like this:

PATH="$JAVA_HOME:$PATH"; export PATH

or this

export PATH="$JAVA_HOME:$PATH"

and you should be OK ... also get rid of the : in front of $JAVA_HOME if you are going to put it in the front of path...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.