Testing for the presence/absence of a pattern in a file, using /bin/sh:
while read a;
do
b="${a##*pattern*}";
[ "$b" = "" ];
done < file
This returns 0 if there's a match. That signal ($?) can then be used outside the loop.
However this method reads through the whole file, even if the match was found in, e.g., line 1.
Can we make it more like sed '/pattern/q' or grep -m1 "pattern"? That is, as soon as we have a match, stop.
How can we break out of the loop after the first successful match**, but still return a value that can be used outside the loop?
** Ideally, there will only ever be one match, because this script is in fact being used to prevent adding duplicate lines to a file.