I want to return failure from my script if a string is NOT found in a file, but I can't work out how to negate my "if". At the moment I have :
if (egrep -i 'search string' filetosearch); then
echo "found"
else
return 2
fi
How can I get rid of the echo bit and just test for "string not found" ? I already know I can use egrep -v to return lines not containing the string, but I actually just want to fail if the search string is not in the file anywhere. Thanks.
There is also && "and" which operates the other way around.
(I added redirection to /dev/null as egrep is used simply for its return value here. You don't want it to actually print any matches. If your egrep has the -q option, you could use that too.)