After editing several PHP files in a directory structure I use this script to check for syntax errors. I have developed and translated several language packages for osCommerce webshop software using this script. You can probably use the structure of this script to traverse down a directory tree and do other things with found files. Please tell me if I presented the script in the wrong way
Code: Select all
# This shell script syntax checks all PHP files from the specified directory
# and downwards and print the file name and the error found, and a summary.
# Remember to save this file with the name php_check and run the command
# chmod 755 php_check to make the file executable.
# Written by Bertil Palmqvist 2016.
if [ "$#" -eq 0 ]
echo "Usage: php_check directoryname"
for x in `find ./$1 -type f`
filetype=`file -b $x`
ft=`echo $filetype | cut -c1-3`
if [ "$ft" == "PHP" ]
bercheck=`php -l $x`
bercheck_begin=`echo $bercheck | cut -c1-2`
if [ "$bercheck_begin" == "Er" ] # No if no syntax error, Er if error
k=`expr $k + 1`
i=`expr $i + 1`
j=`expr $j + 1`
echo $i "PHP files with No syntax errors"
echo $k "PHP files with Parse error/Syntax error"
echo $j "other files than PHP files not checked"