Q:

Why is my Bash script with grep not working?

I'm trying to understand why this very simple script is not working:
echo "SomeText" > test
if [[ "grep 'FindMe' ./test" ]] ; then
  echo Why is this line written to screen?
fi

I have tried with:
"grep 'FindMe' ./test"
$(grep 'FindMe' ./test)
`grep 'FindMe' ./test`
also with a lot of grep options.
I have tried with [] and [[]] and {} and any combination.

A:

In fact, to check the exit status, use no parentheses and no quotes:
if grep 'FindMe' ./test ; then

Using grep -q is common in such situations as we don't want the output of the script to be cluttered with random matches.

