if else if - having problem

Hi Guys,

This is my code of if else if

echo "length=$length";
echo $fun_RTYPE;
if [ "$length" -eq "1" ] -a [ "$fun_RTYPE" -eq "RW" ]
then
VALUE_V=$(echo "scale=4; $VALUE_V * $child_value" | bc);
echo "value_outer=$VALUE_V";
else if [ "$length" -eq "1" ] -a [ "$fun_RTYPE" -eq "RP" ]
        then
                level_new=`expr $level_new + 1`;
                VALUE_RP=`expr $VALUE_V / 100`;
                echo "value_inner=$VALUE_V";
                #echo $VALUE_RP;
                function_recur $TOP_ID $FATHER_ID $level_new $VALUE_RP;
        fi
fi

This is from the log of the script.
length=1 RP value_outer=45.000000
Even though the length is 1 and RTYPE is RP. It is not going in the second if part..

Please correct me where i am going wrong.

Thanks for your help in advance.
Regards,
Magesh.

Few changes in your program, Try now...

echo "length=$length";
echo $fun_RTYPE;
if [ "$length" -eq 1 ] -a [ "$fun_RTYPE" = "RW" ]
then
VALUE_V=$(echo "scale=4; $VALUE_V * $child_value" | bc);
echo "value_outer=$VALUE_V";
else 
        if [ "$length" -eq 1 ] -a [ "$fun_RTYPE" = "RP" ]
        then
                level_new=`expr $level_new + 1`;
                VALUE_RP=`expr $VALUE_V / 100`;
                echo "value_inner=$VALUE_V";
                #echo $VALUE_RP;
                function_recur $TOP_ID $FATHER_ID $level_new $VALUE_RP;
        fi
fi

Why dont u use elif?

stilll not going to the inner if... (i hope u just added the indention after else)..

length=1 RP value_outer=45.000000

if [ "$length" -eq 1 -a "$fun_RTYPE" = "RW" ]

if [ "$length" -eq 1 -a "$fun_RTYPE" = "RW" ]

OR

if [ "$length" -eq 1 ] && [ "$fun_RTYPE" = "RW" ]

Ohh I overlooked that. :frowning:

thanks that worked like magic..