manowar_manowar
manowar_manowar

Reputation: 1150

Grep command for find single equal operator in php files

I want search misused php if statements with grep command in Linux /var/www directory .

//Misused--- i want to find only it
if($a=1){ echo "x"; }

//Correct
if($a==1){ echo "x"; }

Upvotes: 0

Views: 36

Answers (1)

Cyrus
Cyrus

Reputation: 88909

With GNU grep:

grep -E '\bif *\( *\$[^=]+*\b=\b[^=]+\)' file

See: The Stack Overflow Regular Expressions FAQ

Upvotes: 1

Related Questions