title: Replace shell environment variables in a string with actual values
body: <p>I am reading a property file in Java.</p>
  
  <pre><code>Properties myProp = new Properties();
  InputStream in = new FileInputStream(pathOfPropertyFile);
  myProp.load(in);
  in.close();
  </code></pre>
  
  <p>The values in the property file have references to Linux shell variables.
  For example, an entry in the property file might look like:</p>
  
  <pre><code>DATA_PATH=/data/${PROJECT}/${YEAR}${MONTH}${DAY}
  </code></pre>
  
  <p>I have to execute a shell script from java and so I have <strong>ProcessBuilder</strong> instance and also the environment variables (<code>envMap</code> as given below):</p>
  
  <pre><code>List&lt;String&gt; command = new ArrayList&lt;String&gt;();
  command.add(actualCommand);
  command.add(param1);
  command.add(param2);
  ProcessBuilder processBuilder = new ProcessBuilder(command);
  Map&lt;String, String&gt; envMap = processBuilder.environment();
  </code></pre>
  
  <p>The <code>envMap</code> has the environment variables I require  along with over one hundred (> 100) other environment variables which I do not require.</p>
  
  <p>I want to replace the <code>${USER}</code>,<code>${PROJECT}</code>,etc., from the property-value string <code>"/home/${USER}/${PROJECT}/data"</code> with actual values from the shell.</p>
  
  <p><em>I would consider iterating the Map as the last option(as the Map has between 100 and 200 elements to iterate) as it is not an efficient approach.</em></p>
  
  <p>Please advise some approach that will fetch the environment variable enclosed by braces from the string, so that I can directly use the get() of the Map and replace. Or, any better approaches are most welcome.</p>
  
  <p>Note:  The reference offered ( <a href="https://stackoverflow.com/questions/18601011/replace-string-values-with-value-in-hash-map">Replace String values with value in Hash Map</a>  that made my question to look duplicate) is not the best fit in my case.</p>