problem with shell variable's scope

Hi,
I am stuck while developing a shell sub-routine which checks the log file for "success" or "failure". The subroutine reads the log file and checks for key word "success", if found it set the variable (found=1). It returns success or failure based on this variable.

My problem is, I can see the variable being set to 1 (success scenario) but once it comes outside the while loop the value is reset to 0.
Here is the my logCheck function, please let me know where I am wrong.

function logCheck
{
found=0; #sets to 1 if "success" is found

 cat $\{OUTPUT_LOG\} |
 while read line
  do
       temp=\`echo $line|grep "$\{SUCCESS_MESSAGE\}"\`
       if [ $? -eq 0 ];then
           found=1 <-- value is 1 here
           echo "string is found"
           echo "found value inside while is : $found"
      fi
  done

echo "found value outside while is $found" <-- found is 0 in all case
if [ $found = 1 ];then
return $SUCCESS;
else
return $FAILURE
fi
}

//output for success scenario:
string is found
found value inside while loop : 1
found value outside while loop is 0

In all shells except ksh, all segments of a pipeline are executed in subshells.

Please put code inside

 tags.



function logCheck

[/quote]

[indent]
The standard syntax for defining a function is:

logCheck()

UUOC.

UUOG.

Use a case statement rather than an external command:

case $line in
     *"${SUCCESS_MESSAGE}"*) found=1
               echo "string is found"
esac

Thanks a lot Johnson.. have incorporated the changes and its working fine now...