I am trying to set an environment variable using a java code. When i run this java code from the bash, I want to echo the environment variable that i set in the java program. How can this be done

1 Answer 1


If you're talking of something like this:

$ java Foo
$ echo ${var_set_by_foo}

This cannot be done. A process cannot affect another's environment, and a Java program is perforce run as a separate process from your shell.


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.