The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 01-03-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by cjjoy View Post
Hi,
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.

In all shells except ksh, all segments of a pipeline are executed in subshells.
Quote:
Here is the my logCheck function, please let me know where I am wrong.

Please put code inside [code] tags.
Quote:
Code:

function logCheck

The standard syntax for defining a function is:


Code:
logCheck()

Quote:
Code:

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

     cat ${OUTPUT_LOG} |

UUOC.
Quote:
Code:
     while read line
      do
           temp=`echo $line|grep "${SUCCESS_MESSAGE}"`

UUOG.

Use a case statement rather than an external command:


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

Quote:
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

Last edited by cfajohnson; 01-04-2009 at 05:46 PM..