I have to set an environment variable separated by dot in my tomcat startup script. For example


I know shell doesn't accept dot separated variables. Is there a work around ?

I found somewhere that we can use env variable but that doesnt seem to work. I used

env host.name=localhost

Can anyone help me please ?

2 Answers 2


Thanks a lot for your reply AB. However i found a much better solution. I simply added in the CATALINA_OPTS variable of tomcat in the file /usr/share/tomcat7/bin/setenv.sh:

export CATALINA_OPTS="-Dhost.name=localhost"

This worked exactly as I wanted.


I do not understand why that is required for Tomcat. All configuratios are in eg: /etc/tomcat7/server.xml. I have worked for several years with Tomcat, but this kind of configuration I've never needed. Anyway here is your answer.


env "host.name=localhost"

Test with:

env "host.name=localhost" perl -le 'print $ENV{"host.name"}'

or with Java:

Create a runnable jar

package stackoverflow;

import java.util.Map;

public class PrintEnv {
    public static void main(String[] args) {
        Map<String, String> env = System.getenv();
        for (String envName : env.keySet()) {
            System.out.println(envName + ": " + env.get(envName));

and test with:

env "host.name=localhost" java -jar PrintEnv.jar | grep host.name

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .