Problem in While loop

Hi Guys,

This is my code.. I am getting an error in the inside while statement when comparing.. I am not able to figure it out.. Pls help me...

while read value fatherid son_id top_id r_type
do
inside_value=1;
echo $inside_value;
echo $r_type;
while [ $r_type -ne 'RW' ]
do
echo "select value,FATHER,NSON,TOPID,rtype from table1 where FATHER=$son_id and TOP=$top_id with ur" > inside.dat;
read inside_value inside_father_id inside_son_id inside_top_id inside_r_type < inside.dat;
value = expr (inside_value/1000)*value;
top_id=inside_top_id;
son_id=inside_father_id;
done
echo $value $top_id $son_id $fatherid;
done < b.dat;

The error is RP.ksh[2]: 0403-057 Syntax error at line 17 : `"' is not matched.

Thanks for your help in advacne..

Regards,
Magesh.

This looks like a blend of bits of unix shell script and Oracle sqlplus commands.
Shell commands do not need a semi-colon at the end of the command unless there is another shell command on the same line.
Commands for sqlplus do need a semi-colon but need to be presented to sqlplus not shell.

There is actually a shell syntax error on most of the lines. The level of problem depends on whether some of the commands should be processed by Oracle sqlplus or not.

What is the script meant to do?
Is there a database involved, or are you trying to run Oracle sqlplus syntax commands in shell?

What is in file "b.dat" ?

Maybe your file is dosfile.

try:
cat file | tr -d "\015" > newfile
and run newfile.

Looks like there is a problem with the below statement.

value = expr (inside_value/1000)*value;

Try this way

value=`expr $inside_value / 1000 \* $value`

Guys,, sorry wasn well so unable to reply to all...

@methyl
yes, actually this is blend of unix and db2,,, actually i have fixed the error.. But now the expr command is actually causing a problem..

@sriharsha_kvr
thanks for ur suggestion.. But i need to include a bracket to make sure the order of execution of the operations.. Can you please guide me how to do it?

In this case you don't need ( ).

expr  $value  \*   $inside_value  /  1000
expr  $inside_value  /  1000  \* $value
expr \( $inside_value  /  1000  \)  \* $value

give same result

expr need arguments = argument delimeter between arguments.
It's always commandline = shell parse file generation, ... (in this case *), and ( ) is subshell. So we have to tell for shell = don't parse ( ) *

You can do integer calculation using shell, no need to ex. expr. Only old bsh can't do it.
ksh99, bash, ... can do it, ksh also using floating. Bash, expr, ... only integers.

Shell (all posix compatible sh):

(( value = ( inside_value / 1000 ) * value ))

bc is also real calculator, also floating support, in this case:

value=$( echo "($inside_value / 1000 ) * $value" | bc  )

thanks both the solutions are working fine.. thanks dude..