if condition for variable existing in file

Hi, Sorry for the dumb question but I can't seem to figure this one out. I want to write an if condition that basically checks if my variable is in a file. So far I have the following:

if [[ grep var file ]]
then
do something
else
do something else
fi

So essentially if the grep returns something then I want it to do the first condition else do something different but when I run it it keeps erroring on me

your very close. you should inline the command into the condition.

# -q = quiet mode. just set return code
# -w = word match - may or may not apply to your situation

if grep -q -w var file
then
   do something
else
   do something else
fi

Thanks for the quick response but do I need to have the [[ ]] around the condition? I'm getting a syntax error:

./Compare.sh: line 9: conditional binary operator expected
./Compare.sh: line 9: syntax error near `-q'
./Compare.sh: line 9: ` if [[ grep -q -w var file ]]'

no. you should use exactly what I posted.