title: In Scala, read a file where specified path includes multiple environment variables
body: <p>For a file path name such as</p>
  
  <pre><code>val path = "$HOME/projects/$P1/myFile.txt"
  </code></pre>
  
  <p>is there a simpler way to resolve the path and read <code>myFile.txt</code> than this,</p>
  
  <pre><code>import java.io.File
  val resolvedPath = path.split(File.separator).map{ s =&gt; 
        if (s.startsWith("$")) sys.env(s.drop(1)) 
        else s }.
      mkString(File.separator)
  
  val res = io.Source.fromFile(resolvedPath).getLines
  </code></pre>