Daily Archives: June 27, 2013

How to run php inside a bash script

bash

php
Yes…you CAN run a php script inside a bash script. (or any other programming language actually, inside a bash script). The syntax is shown below. Now I’m not sure that it’s always wise to do that, but it’s interesting that you can do that 🙂

I actually needed the output of a php script inside the bash script and didn’t want to have to rewrite the entire php script in bash, and didn’t want to rewrite the shell script in php, so I just decided to include the php script inside the bash script to make it quicker to complete. Worked like a charm. Thought I’d share the way I did that.



#!/bin/bash
# Run php scripts inside bash

FUNCTIONANAMEHERE ()
{
/usr/bin/php -q <<'EOF'
EOF
}

#call function here
FUNCTIONAMEHERE;