I don't think my question has been asked before (not exactly anyway, if it has, apologies). I am using Tomcat 7 on CentOS 7.

In my tomcat/bin/setenv.sh file I have set:

export TEST="test"

Then I start tomcat via Terminal by running tomcat/bin/startup.sh

Then I run (not in a script, just in the Terminal after I have executed the Tomcat startup script):

echo $TEST

My question: Should I be able to "echo" the variable TEST? Should I be able to see that the TEST variable has been set to what I want it to be (test)?



The startup.sh script may be sourcing the setenv.sh file to get the variable's value, but if it does, the variable will only be set within the environment of the startup.sh script, not in you interactive shell.

If you want to see what's happening when you run startup.sh, first determine what shell interpreter it's using (see the #!-line at the top of the file).

If it's bash, run it with

$ bash -x tomcat/bin/startup.sh

(i.e. add -x to the command line)

This will turn on tracing of the script.


No. startup.sh runs in a different process than the process from which you launch it. When a script is launched it runs in a new subshell of the current shell. And while it's true that a subshell inherits the environment of its parent during initialization there is no propagation of changes, in either direction, after that time. So when startup.sh does . setenv.sh1 the environment changes are not visible from your command line.

If you instead ran . startup.sh then things would be different as everything would be happening in the same shell. But that's not going to be healthy for your Tomcat startup!

1 Actually startup.sh invokes catalina.sh and it then sources setenv.sh (at least in Tomcat 7.x) but to keep things simple I'm ignoring that fact since it doesn't change the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.