scope of a Variable inside shell script

hi all,

i'm using the following script,

Status=1
Function_do ()
{
while read line;
do
    if [ ` echo $line | grep 'symbol not found:' | wc -l` -eq 1 ]; then
        #echo $line
        if [ ! `echo $line | grep 'kxdfhei1' | wc -l ` -eq 1  -o  ! `echo $line | grep 'main' | wc -l ` -eq 1 ]; then
            Status=0
            echo " LINKINK ERROR "
        fi
    fi
done < ldd.log
}

Function_do
echo " Status = $Status "

OUTPUT:

LINKINK ERROR
Status = 1
What happen to the value of Status=0 that i set inside If condition? What happens if use while? the same script if i use for loop it is giving proper output.. status=0. I'm not able to understand the logic behind it. Can any one help me in this?

Regards,
Vijay

Hi,

I have tried but , I am getting below output.

 Before calling Status = 1
 LINKINK ERROR
 After Calling Status = 0

when i run the above script as sh test.sh its not giving the proper output. But when i rename it to test.ksh and run as ksh test.ksh it is woking. I dont know what is the difference. I'm using Sun Solaris...

If it works fine with ksh, why not sticking with it ?

I guess the issue is /bin/sh running the while loop in a subshell because of the input redirection.

Hi,

It is the behaviour of the borune shell.