grep exact string/ avoid substring search

Hi All,

I have 2 programs running by the following names:
a_testloop.sh
testloop.sh

I read these programs names from a file and store each of them into a variable called $program.
On the completion of the above programs i should send an email.
When i use grep with ps to see if any of these are running i cannot differentiate between the two.

I am using the following command:
ps -ef|grep $program|grep -v grep

The above command succeeds for both the cases even when only a_testloop.sh is running as testloop.sh is a part of a_testloop.sh. I want to grep/search only the exact string not substring. Please help.

Thanks,
Albert

Use the -w option of grep.

Regards

what about
1) grep for a_testloop will give you just that
2) grep for testloop and then grep -v a_testloop to exclude that one

The ps-output is tabular, right?

You can search for whitespace too, if you protect them properly (otherwise the shell will eat them):

# cat myfile
 testloop
 a_testloop

# grep '[<spc><tab>]testloop' myfile
 testloop
# grep '[<spc><tab>]a_testloop' myfile
 a_testloop

Replace <spc> by a literal blank and <tab> by a literal tab character.

I hope this helps.

bakunin