This example shows a simple way of searching for a pattern match in a string and return the decision. For ex: My_exceptions="abc 123" My_string="Hey I am searching for 123" for word in $My_exceptions do [ `echo $My_string |grep $word` ] && match_found="y" || match_found="n" [ $match_found = y ] && break; done This works for environment like Solaris 5.10/5.11, Linux, ksh, bash