1

I'm trying to create a shortcut script for setting some environment variables and the include path before running php -a. So it looks like this:

#!/usr/bin/env php
<?php

putenv("ENVVAR=value");
passthru("php -a -d include_path=<path>");

This mostly works, but the php shell doesn't correctly output its prompt.

I.e. normal output from php -a:

$ php -a
Interactive shell

php > echo "hi\n";
hi
php >

Output from this script:

$ ./myscript.php
Interactive shell

echo "hi\n"; 
hi

Additionally, there is no support for walking through the history (or even right or left along what's already been typed) with arrow keys.

Is there a way to get this to work correctly?

I'm using Mac OS X, PHP 5.4.27. I have already tried redirecting stderr to stdout, in case that was somehow the cause (it wasn't.)

1 Answer 1

1

Rather than writing it in PHP, why not do it as a shell script.

#!/bin/bash

export ENVVAR=value

php -a -d include-path=whatever

I'm using bash, and it works fine under Ubuntu 12.04. I'm not sure what shell is available on OSX.

Sign up to request clarification or add additional context in comments.

2 Comments

I might end up doing this, because it would work in this particular case - but I'd like to (hypothetically) have this script have multiple subcommands and run more complex php code for some of them.
OS X has a similar shell to Ubuntu. They're both Unix-based OSes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.