title: Set environment variable from outside bash
body: <p>I'm trying to set a bash environment variable using PHP (from command line) with no success. </p>
  
  <pre><code>$buff=array();
  $buff[]="VARTESTKEY=VARTESTVALUE";
  $buff[]="export VARTESTKEY";
  file_put_contents('script.sh', implode("\n",$buff));
  system('source script.sh');
  </code></pre>
  
  <p>I've even tried using a script to output the key value which gets evaled:</p>
  
  <pre><code>$buff=array();
  $buff[]="echo VARTESTKEY=VARTESTVALUE";
  file_put_contents('script.sh', implode("\n",$buff));
  system('eval "$(bash script.sh)"');
  </code></pre>
  
  <p>But still nothing.</p>
  
  <p>Any ideas? I don't mind using any other tool (perl, python, c, etc.) as long as it can do its job by being called from the PHP system function.</p>