Posted on 2 Comments

Assigning PHP variables in shell

Google Logo

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.

  1. Determine path to PHP:
  2. Include any required configuration files:
  3. Finally assign PHP variables to shell:

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.

2 thoughts on “Assigning PHP variables in shell

  1. Ich bin eben das erste mal vorbei gekommen. Gefaellt mir ziemlich gut.

    1. Danke, das freut mich zu hören 😛

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.