Using exact matching with grep in Shell program

I writing a shell script, and in the script I would like to grep to perform an exact string match in another file.  Whenever I try to do this, the variable that I save the grep return in does not give the right results when checking that value.  Can someone please tell me if I am missing something.  Below is the portion of the code that I am working with.

serial="test1"
output=./script_report

check=`grep -m 1 -w "$serial" $output`

if [ "$check" != "" ]
then
........

When this function is run and "test1" does not exist within the file but a the string "test" does exist, the conditional returns true.  (should return false)

Thanks for the help.
sctccommAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
It is returning false when I try it
0
 
sctccommAuthor Commented:
Okay, I fixed the problem, the grep work fine the way it is.  Just forgot to update the value of check after the first time.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.