Using grep in a test/if statement

Okay, well this is more or less my first attempt at writing a shell script.

Anyways, here's my code:

cd ${PATH}

if [ 'grep SOME_STRING $PATH/$LOGFILE' ]
then
        rm ${FILE}       
        ./anotherScript
else
        exit 1
fi
exit 1

Anyways, it's a pretty simple script that is supposed to search for the string SOME_STRING in a log file, and if it finds it, then perform the next two steps of removing a file and running another script. If it doesn't find the string, then the script just exits. I tested it, it found the string, and it worked. But then I double checked and tested it when I knew the string wasn't present in the log file, and it still ran the script, instead of exiting.

cd ${PATH}

if [ $(grep -c SOME_STRING $PATH/$LOGFILE) -ne 0 ]
then
        rm ${FILE}       
        ./anotherScript
else
        exit 1
fi

exit 0

For really large files all you want is a yes/no instead of reading thru the whole file.

cd ${PATH}

grep -q SOME_STRING $PATH/$LOGFILE
if [ $? -eq 0 ]
then
        rm ${FILE}       
        ./anotherScript
else
        exit 1
fi

exit 0

grep -q exits as soon as it gets a hit.

Otherwise shamrock's code is just fine.

Thanks for all your help. Got it the first way, tomorrow I'll try it the second way b/c these files can get quite big.

Thanks again, I'm sure i'll be on here more often now.

grep -l "test" test* | xargs -i rm "{}" && ./script.sh