The script I am trying to run via shell_exec in PHP requires an environmental variable to be set, which afaik is done via:
export VARIABLE=value
However, to run the script I am forced to do:
<?PHP
$sOutput = shell_exec("export VARIABLE=value && my_command_goeth_hereth");
It seams kinda pointless to have to export the variable every time I run any commands.
Is this the only way to do it, or am I missing a much simpler way?
Won't just:
do the trick?
If you're running multiple shell scripts, then putenv is your friend, as zneak pointed out.
EDIT with an exmaple:
env.php:
runenv.php:
then try
$ php runenv.php
Since environment variables are inherited, setting them inside your script will set them for the commands it launches too. You just have to use
putenv
.