title: Setting and getting environment variables by "source" a shell script from Java code
body: <p>I'am writing Java console application which takes input parameters from environment variables (Linux). To set these variables, my application must "source" the shell script. I can "source" the script by using Runtime.exec() or with ProcessBuilder, but I have no idea how to get access to created environment variables. </p>
  
  <p>There is my shell script (set_env.sh):</p>
  
  <pre><code>#!/bin/csh
  
  setenv MY_DB DB_NAME
  </code></pre>
  
  <p>There is Java code to "source" the script above:</p>
  
  <pre><code>    ProcessBuilder pb = new ProcessBuilder("csh", "-c", "'source set_env.sh'");
      Process p = null;
      try {
          p = pb.start();
          p.waitFor();
      } catch (IOException | InterruptedException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>How can I get access to created MY_DB variable or is there any other solution of my problem?</p>
  
  <p>Any help will be very appreciated.
  Thank you in advance. </p>
  
  <p>Ok guys. Thanks to your answers. There is my temporary solution. I've written another script that makes "source" and echoes created variables. In the Java code I'am executing it, reading process's inputstream and parse them then.</p>