enviroment variables in ksh

enviroment variables in ksh

Post by Frank Apa » Wed, 30 Oct 2002 03:41:14



Hi, Im trying to write a ksh script that when run changes the enviroment
variables for that session.  What i mean i want to run the script and then
until i logout and log back in I want to use the new settings.  Here is the
script thats not working:

#!/bin/ksh

JHOME="/usr/java$1"

echo "Changing JAVA_HOME to $JHOME"
export JAVA_HOME=$JHOME
echo "Adding $JHOME/bin to PATH"
export PATH=$JHOME/bin:$PATH

echo "New JAVA_HOME $JAVA_HOME"
echo "New PATH $PATH"

This is what happens when i run it

$ ./change_java 1.1
Changing JAVA_HOME to /usr/java1.1
Adding /usr/java1.1/bin to PATH
New JAVA_HOME /usr/java1.1
New PATH
/usr/java1.1/bin:/usr/java1.3/bin:/usr/bin::/opt/oracle/product/817/bin
$ echo $JAVA_HOME
/usr/java1.3

As you can see the value of JAVA_HOME reverts back after the script is
executed...how do i avoid this?

THanks!

 
 
 

enviroment variables in ksh

Post by Greg Andre » Wed, 30 Oct 2002 03:52:38



>This is what happens when i run it

>$ ./change_java 1.1
>Changing JAVA_HOME to /usr/java1.1
>Adding /usr/java1.1/bin to PATH
>New JAVA_HOME /usr/java1.1
>New PATH
>/usr/java1.1/bin:/usr/java1.3/bin:/usr/bin::/opt/oracle/product/817/bin
>$ echo $JAVA_HOME
>/usr/java1.3

>As you can see the value of JAVA_HOME reverts back after the script is
>executed...how do i avoid this?

It does this because your the ksh that's taking your interactive
commands (like "./change_java 1.1") runs another ksh shell to
execute the script.  The child ksh that's executing the script
can only change its own environment variables.  It cannot change
the variables in its parent ksh.  So the parent ksh, the one
taking your commands, keeps its original environment variable
settings.

You need to tell the ksh that's taking your commands to run
the commands in the script itself, rather than invoking a
child ksh.  You do that with ksh's '.' command:

  .  ./change_java 1.1

  -Greg
--
Do NOT reply via e-mail.
Reply in the newsgroup.

 
 
 

enviroment variables in ksh

Post by Allen M. Cohe » Wed, 30 Oct 2002 11:25:07


Or you could exec another ksh sub-shell at the end of your script...



> >This is what happens when i run it

> >$ ./change_java 1.1
> >Changing JAVA_HOME to /usr/java1.1
> >Adding /usr/java1.1/bin to PATH
> >New JAVA_HOME /usr/java1.1
> >New PATH
> >/usr/java1.1/bin:/usr/java1.3/bin:/usr/bin::/opt/oracle/product/817/bin
> >$ echo $JAVA_HOME
> >/usr/java1.3

> >As you can see the value of JAVA_HOME reverts back after the script is
> >executed...how do i avoid this?

> It does this because your the ksh that's taking your interactive
> commands (like "./change_java 1.1") runs another ksh shell to
> execute the script.  The child ksh that's executing the script
> can only change its own environment variables.  It cannot change
> the variables in its parent ksh.  So the parent ksh, the one
> taking your commands, keeps its original environment variable
> settings.

> You need to tell the ksh that's taking your commands to run
> the commands in the script itself, rather than invoking a
> child ksh.  You do that with ksh's '.' command:

>   .  ./change_java 1.1

>   -Greg
> --
> Do NOT reply via e-mail.
> Reply in the newsgroup.

 
 
 

1. ksh: Need to read variables into variables

Inside a utility shell I have the statement:

  read TPL_LOC?" > " # get template path from user

I want to enter

 > $TPL_HOME/admin

where $TPL_HOME is a standard system variable and have $TPL_LOC
interpreted the same way it is on my command line.

The line

  TPL_LOC="$TPL_HOME/admin"

works, but I do not have the luxury of being able to hard code this. The
users of the utility need to enter their own pathnames.

Anyone have any ideas?

--
Andree Fontenot

"It isn't necessary to change; survival is not mandatory." - W. Edwards
Deming

2. InfoMagic Mar Issue...

3. Using a variable in a variable name in KSH

4. PLEASE HELP!

5. Sample ksh enviroment

6. Update DNS server via client?

7. How to set up ksh in a chroot()ed enviroment

8. new usb hub => new lock up

9. What's 'side effects' of Ksh built-ins?

10. Is it possible to spoof Apache enviroment variables?

11. Help needed setting enviroment variables

12. Quick question about enviroment variables

13. How to set TEXINPUTS enviroment variables?