Jump to content

[SOLVED] Sourcing Bash variables from PHP?


trq

Recommended Posts

I'm trying to create a nice clean $_ENV array as part of a Linux package management system I'm building with php, but Im having a hard time finding out when exactly it is that php's $_ENV array is built.

 

I have this bash file (env.sh).

 

#!/bin/bash

FOO="this is foo" ; export FOO

 

And this php file (envtest.php)

 

#!/usr/bin/bash
<?php

  exec("source env.sh");
  print_r($_ENV);

?>

 

Executing this...

 

$ ./envtest.php | grep FOO

 

I get nothing.

 

Executing...

 

$ FOO="this is foo" ; export FOO ; ./envtest.php

 

I still get nothing, but....

 

$ FOO="this is foo" ; export FOO ; php -r 'print_r($_ENV);' | grep FOO

 

returns...

 

[FOO] => this is foo

 

Anyone tried this before? Whats gives?

Link to comment
https://forums.phpfreaks.com/topic/50296-solved-sourcing-bash-variables-from-php/
Share on other sites

Yeah...its been a while since Ive posed a question. Anyway, Ive figured out the problem. It appears exec spawns another process, hence FOO is being set, but not within the same environment as my script.

 

It would also appear that there is no work around for this. Looks like I will be writing this application in Python instead. Not real impressed, but you get that on big jobs I suppose.

 

I was so hoping PHP might be up to the task.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.