Assigning PHP variables in shell
For a project I am currently working on it was necessary to read PHP define()’d-values from a configuration file using a shell script that did some further processing.
In order to be able to read define()’d-values you need to first include() (or better require_once()) the source configuration file(s) and then assign its values to shell variables.
- Determine path to PHP:
- Include any required configuration files:
- Finally assign PHP variables to shell:
RELEASE_NUMBER=`$PHP_PATH -r "$PHP_REQUIRE echo RELEASE_VERSION;"`
Hint: In case your PHP installation is included in PATH you can simply write PHP_PATH=”php”.
In this example the release version number is read from a base-configuration file, which will be used by the shell script for further processing.