calling plsql function in a unix script

Could anyone please help me. I have a function in plsql that returns a number. But i am listing some records through that function using DBMS_OUTPUT.PUT_LINE. I want to catch those records by executing this function through a unix script. The following shows what i did

echo "Connected from $CONN_STR instance "
echo "\
set pagesize 0
SET SERVEROUTPUT ON SIZE 999999
set feedback on
declare
g number;
begin
g:=lui50.PKG_HUI_SLS_OSM.FN_OSM_LST_DUPL_REC;end;"|$SQLPLUS -s $USERPASS | read list
echo " There are $list records in the table";

But the variable is not catching the records listed through the function.

Can anyone help me please urgently.

change the last bit to

 |while read list; do echo "There are $list records in the table"; done

the read is running in a different child process due to the piping.

You could also try rearranging the input as follows

$SQLPLUS -i $SQLPASS <<EOF
set pagesize 0
SET SERVEROUTPUT ON SIZE 999999
set feedback on
declare
g number;
begin
g:=lui50.PKG_HUI_SLS_OSM.FN_OSM_LST_DUPL_REC;end;
EOF

to achieve similar.

Thanks for the reply. I shall try the first one. But the second one is just executing the function, not catching the values.

Thank you so much