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)?


No. startup.sh runs in a different process than the process from which you launch it. Specifically, when a shell script is launched it runs in a newly created subshell of the current shell. And while it's true that subshells (and all other processes) inherit the environment of the parent during initialization there is no propagation of changes, in either direction, after that. So when startup.sh does . setenv.sh1 the environment changes are not visible from your command line.

If you think about it, you really don't want things to work the other way. Your working shell, once you get control of it back, will be "polluted" with who knows what kind of environmental changes. For example, the Tomcat scripts might completely change $PATH and break a bunch of things for you in the process.

1 Actually startup.sh invokes catalina.sh and it then sources setenv.sh (at least in Tomcat 7.x) but to keep things simple we'll disregard that as it doesn't change the result.


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 your 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)

Adding the -x option to the invocation of the shell will turn on the tracing of the script.

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.