Bash Script for PHP Lint always returning 0

400 views Asked by At

EDIT: THIS WORKS NOW. I copied this into a my CentOS box and it works like a charm. I was testing this script on Windows and it only returns 0 (even when PHP LINT gives an error)

This bash script is supposed to perform a PHP LINT CHECKER. No matter which files I feed the php -l, it always returns 0 (success). I have even purposely cause one of my files to have a syntax error (missing semicolon), but it still returns 0.

For testing purposes, I have php -l stored in a variable $STUFF and have it return what if the return status of php -l is 0

I have tried numerous other methods but php -l keeps returning 0 (success)

#!/bin/bash

DIFF_FILES=$(git diff --cached --name-status --diff-filter=AM | awk '{print $2}')

function syntaxChecker() {
    for files in $DIFF_FILES; do
        STUFF=$(/c/PHP/php -l $files)
        if [ $STUFF -eq 0 ]; then
            echo 'what'
        fi
done
}

syntaxChecker
1

There are 1 answers

5
Ignacio Vazquez-Abrams On

For testing purposes, I have php -l stored in a variable $STUFF and have it return what if the return status of php -l is 0

That's not what your code says. Your code stores the output of php -l and then compares that with 0; the return status of a command is stored in $?. And as always you can check for a non-zero return status directly in if.

if php -l ...