Developing software in the Real World

Recursive PHP lint

There are many scripts that recursively execute php -l on a set of files or directories. This is mine:

I store it in ~/bin and usually run it like this:

There are a few interesting bash tricks that I picked up when I wrote this.

Firstly, you need to set IFS to break on new line rather than space otherwise the find command doesn’t work with spaces in file names.

I also discovered that the output of php -l has quite a lot of blank lines in its output that I didn’t want. OUTPUT=$(echo -e "$OUTPUT" | awk 'NF') solves this nicely.

I also wanted to indent the output and used bash’s parameter expansion system to replace a new line with a new line and two spaces using ${OUTPUT//$'\n'/\\n }

Maybe you’ll find this useful or it’ll work as the basis for a script you need to write.

2 thoughts on “Recursive PHP lint

  1. This is mine:

Thoughts? Leave a reply

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