I can write a shell script that will set an enviroment variable using the export command, but then when i try and print the variable after the shell scrit has been run the variable is no longer set. Why is this? my problem is that i need to set some enviroment variables in a shell script that is run when my tomcat server is started, but after the startup script runs the variables are no longer set. Here is what i am using in my scripts:
export CLASSPATH=/usr/root/ echo $CLASSPATH
but then when i do a echo $CLASSPATH from the command line the original value is printed and not the one set in the shell script.
any help would be great.
On 08/06/2006 08:40 AM, Ryan Ollerenshaw wrote:
I can write a shell script that will set an enviroment variable using the export command, but then when i try and print the variable after the shell scrit has been run the variable is no longer set. Why is this? my problem is that i need to set some enviroment variables in a shell script that is run when my tomcat server is started, but after the startup script runs the variables are no longer set. Here is what i am using in my scripts:
export CLASSPATH=/usr/root/ echo $CLASSPATH
but then when i do a echo $CLASSPATH from the command line the original value is printed and not the one set in the shell script.
any help would be great.
When you run a script from bash it will be run in a new bash process and so all environment variables will be set in that new shell. To avoid it and make your script run in current shell, use "source" builtin command (or equivalent "."), e.g.
source test.sh
or
. test.sh
More detail in man bash (look for "SHELL BUILTIN COMMANDS" -> "source").
Regards, Dariusz
Ryan Ollerenshaw writes:
I can write a shell script that will set an enviroment variable using the export command, but then when i try and print the variable after the shell scrit has been run the variable is no longer set. Why is this? my problem is that i need to set some enviroment variables in a shell script that is run when my tomcat server is started, but after the startup script runs the variables are no longer set. Here is what i am using in my scripts:
export CLASSPATH=/usr/root/ echo $CLASSPATH
but then when i do a echo $CLASSPATH from the command line the original value is printed and not the one set in the shell script.
any help would be great.
Use the "." command. So, instead of running foo, run
. foo
Andrew.
Andrew Haley writes:
Ryan Ollerenshaw writes:
I can write a shell script that will set an enviroment variable using the export command, but then when i try and print the variable after the shell scrit has been run the variable is no longer set. Why is this? my problem is that i need to set some enviroment variables in a shell script that is run when my tomcat server is started, but after the startup script runs the variables are no longer set. Here is what i am using in my scripts:
export CLASSPATH=/usr/root/ echo $CLASSPATH
but then when i do a echo $CLASSPATH from the command line the original value is printed and not the one set in the shell script.
any help would be great.
Use the "." command. So, instead of running foo, run
. foo
Allow me to recommend http://www.amazon.com/gp/product/013937681X
Andrew.
java-devel@lists.fedoraproject.org