title: Set environment variable in shell script and access in Java program
body: <p>This question is a followup on <a href="https://stackoverflow.com/questions/10140182/set-environment-variable-in-shell-script-access-in-java-program">Set environment variable in shell script/access in Java program</a>. I am trying to fetch the environment variable in Java after running a shell script but unable to do so</p>
  
  <p>Shell Script: getDetails.sh:</p>
  
  <pre><code>#!/bin/bash
  # File: getDetails.sh
  export userDetails="USER123"
  # echo "User Details for App :$userDetails"
  </code></pre>
  
  <p>Java method:</p>
  
  <pre><code>String details = new String("source " + "getDetails.sh");
  ProcessBuilder processBuilder = new ProcessBuilder("/bin/bash", "-c", details);
  Process getPwdProc = processBuilder.start();
  System.out.println("Details - " + processBuilder.environment().get("userDetails"));
  </code></pre>
  
  <p>The java method returns/prints null for the environment variable - userDetails.</p>
  
  <p>P.S. - Please note that the use of InputStream/BufferedReader to read the userDetails is not possible here as echoing the details is not allowed for the program/organization.</p>