title: OS X Mountain Lion: how set system-level environment variable with referenced value?
body: <p>According to posts here such as <a href="https://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x">Setting environment variables in OS X?</a>, for Mountain Lion, if not for earlier version of OS X, the only way to set environment variables at the <em>system</em> level is to use (or create) a file /etc/launchd.conf that contains commands such as:</p>
  
  <pre><code>setenv CATALINA_BASE /opt/local/share/java/tomcat6
  </code></pre>
  
  <p>(That does seem to work as expected.)</p>
  
  <p>If so, how does one do this by referencing the value of something else, e.g., to set JAVA_HOME? In /etc/launchd.conf I tried</p>
  
  <pre><code>setenv JAVA_HOME $(/usr/libexec/java_home)
  </code></pre>
  
  <p>but then in Terminal if I run</p>
  
  <pre><code>echo $JAVA_HOME
  </code></pre>
  
  <p>I just get back literally $(/usr/libexec/java_home).</p>
  
  <p>By contrast, if I put that same setenv JAVA_HOME $(/usr/libexec/java_home) command into my ~/.profile, then the result of echo $JAVA_HOME is the actual value referenced, namely, /Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home.</p>
  
  <p>So how should I modify the setenv command in /etc/launchd.conf so as to cause it to give the <em>value</em> of the second argument rather than the literal second argument?</p>