Quick and dirty way to run PHP with a double-click

I’m doing more with Things integration and PHP is a quick-and-dirty, but way more powerful than BASH, way to do what I’m trying to do. But tweaking permissions, bang-bash lines, etc., is more than I wanted to deal with. So I’m wrapping some PHP code in a BASH script with a .command extension. This may not be the best way to do this, but, again, quick-and-dirty.

#!/usr/bin/env bash
clear
PHP=`php --version`
EXIT=$?

if [[ $EXIT -ne 0 ]] 
then
	echo "PHP not installed, running brew install php..."
	brew install php
fi

UUID="`uuidgen`"
DIRECTORY="`dirname "$0"`"

cat > /tmp/$UUID.php << 'FNORD_EOF'
<?php
print "Hello, world. Running in directory: " . $argv[1] . "...\n";
print_r($argv);
?>
FNORD_EOF

php /tmp/$UUID.php "$DIRECTORY"
rm /tmp/$UUID.php

Comments