Problem with function script.

Need an extra set of eyes. Can't find function. Can someone help, please. Thanks

echo " Is this the correct list of tapes to eject (y/n)?"
read option
echo $option
case $option in
y|Y) TAPE_ROUTINE;;
n|N) exit
esac

##### Count the number of volumes to eject ########
#### When volume count is 40 go to EJECT_TO SILO ####
TAPE_ROUTINE ()
{
cat $EJECTED_TAPES; echo "ejected these tapes"
TAPE_CT=0
CAP_TOTAL=40
EJECT021=ejectupto40.log
cat /dev/null > $EJECT021

while read volume until EOF
do echo "volume ejected $volume"
TAPE_CT=`expr $TAPE_CT + 1`
echo $TAPE_CT

                    if [ $TAPE_CT < $CAP_TOTAL ]  &&  [ ! EOF ]
                    then
                            cat $volume >>  $EJECT021
                    else
                            echo "eject $TAPE_CT .. CAP is $CAP_TOTAL first cap"
                            EJECT\_TO_SILO 
                    fi

done < $EJECTED_TAPES
}

### Eject tapes to Cap with total count is 40 ####
EJECT_TO_SILO ()
{
# /opt/OMIdtelm/bin/eject_vol -t 3600 -c 0,2,1 -l $EJECT021 | tee $EJECT_LOG;
echo "ejected $volume to cap 0 2 1"; sleep 10
mv $EJECT021 ejected_next_group.txt
/dev/null > $EJECT021
$TAPE_CT =0
}

You must define the function before using it.

#--------------------------------------
# L O C A L   F U N C T I O N S . . .
#--------------------------------------

### Eject tapes to Cap with total count is 40 ####
EJECT_TO_SILO ()
{
# /opt/OMIdtelm/bin/eject_vol -t 3600 -c 0,2,1 -l $EJECT021 | tee $EJECT_LOG;
echo "ejected $volume to cap 0 2 1"; sleep 10
mv $EJECT021 ejected_next_group.txt
/dev/null > $EJECT021
$TAPE_CT =0
} 

##### Count the number of volumes to eject ########
#### When volume count is 40 go to EJECT_TO SILO ####
TAPE_ROUTINE ()
{
cat $EJECTED_TAPES; echo "ejected these tapes"
TAPE_CT=0
CAP_TOTAL=40
EJECT021=ejectupto40.log
cat /dev/null > $EJECT021

while read volume until EOF
do echo "volume ejected $volume"
TAPE_CT=`expr $TAPE_CT + 1`
echo $TAPE_CT

if [ $TAPE_CT < $CAP_TOTAL ] && [ ! EOF ]
then
cat $volume >> $EJECT021
else
echo "eject $TAPE_CT .. CAP is $CAP_TOTAL first cap"
EJECT_TO_SILO 
fi
done < $EJECTED_TAPES
}


#--------------------------------------
# M A I N . . .
#--------------------------------------

echo " Is this the correct list of tapes to eject (y/n)?"
read option
echo $option
case $option in
y|Y) TAPE_ROUTINE;;
n|N) exit 
esac

Jean-Pierre.

Thank-you all for your help.

#--------------------------------------
# L O C A L F U N C T I O N S . . .
#--------------------------------------

### Eject tapes to Cap with total count is 40 ####
EJECT_TO_SILO ()
{
# /opt/OMIdtelm/bin/eject_vol -t 3600 -c 0,2,1 -l $EJECT021 | tee $EJECT_LOG;
echo "ejected $volume to cap 0 2 1"; sleep 10
mv $EJECT021 ejected_next_group.txt
/dev/null > $EJECT021
$TAPE_CT =0
}

##### Count the number of volumes to eject ########
#### When volume count is 40 go to EJECT_TO SILO ####
TAPE_ROUTINE ()
{
cat $EJECTED_TAPES; echo "ejected these tapes"
TAPE_CT=0
CAP_TOTAL=40
EJECT021=ejectupto40.log
cat /dev/null > $EJECT021

while read volume until EOF
do
echo "volume ejected $volume"
TAPE_CT=`expr $TAPE_CT + 1`
echo $TAPE_CT
if [ $TAPE_CT != 40 ]
then
$volume | tee $EJECT021
else
echo "eject $TAPE_CT .. CAP is $CAP_TOTAL first cap"
EJECT_TO_SILO
fi
done < $EJECTED_TAPES
}

#--------------------------------------
# M A I N . . .
#--------------------------------------

echo " Is this the correct list of tapes to eject (y/n)?"
read option
case $option in
y|Y) TAPE_ROUTINE;;
n|N) exit

Almost there, but I can't seem to get my counters right. Anyone can please look and see what I am missing. Thanks

# This scripts ejects IP tapes from the STK9310 silo via ACSLS Commands from plebsb01.
# Scripter : Kathe Flanigan 1/31/07
#!/bin/ksh
set -x
rpt=/export/home/legato/tapemgr/rpts/offsite
dat=`date +"%m%d%y"`
rdat=`date +"%b%d%y_%H%M%S"`
EJECTED_TAPES="$rpt/ejected/eject_tapes_test.041608"
OFFSITE_RPT="$rpt/Offsite.rpt.041608"
EJECT_LOG=$rpt/ejected/ejected_tape.status.log.041608
TOT_TAPE_CT_EJECTED=0
TAPE_CT=0
CAP_TOTAL=40
EJECT40=ejectupto40.log
cat /dev/null > $EJECT040

#--------------------------------------
# L O C A L F U N C T I O N S . . .
#--------------------------------------

### Eject 40 tapes to Cap ####

EJECT_TO_SILO ()
{
echo "EJECT_TO_SILO _ List of tapes to be ejected to cap 0,2,1"; cat $EJECT40 ; sleep 2
TOT_TAPE_CT_EJECTED=`expr $TOT_TAPE_CT_EJECTED + $TAPE_CT`
# /opt/OMIdtelm/bin/eject_vol -t 3600 -c 0,2,1 -l $EJECTED_TAPES | tee $EJECT_LOG;
cat $EJECT40 >> TAPES_EJECTED.log
cat /dev/null >$EJECT40
echo "total tapes eject $TOT_TAPE_CT_EJECTED";sleep 1
TAPE_CT=0
}

##### Count the number of volumes to eject ########
#### When volume count is 40 go to EJECT_TO SILO ####

TAPE_ROUTINE ()
{
while read volume until EOF
do
echo " In tape routine volume ejected $volume"
echo $TAPE_CT
if [ $TAPE_CT != 40 ]
then
echo $volume >> $EJECT40
else
echo "eject $TAPE_CT .. CAP is FULL"; sleep 1
EJECT_TO_SILO
fi
TAPE_CT=`expr $TAPE_CT + 1`
done < $EJECTED_TAPES
EJECT_TO_SILO

#TOT_TAPE_CT_EJECTED=`expr $TAPE_CT + $TOT_TAPE_CT_EJECTED`
echo "Total tapes ejected: $TOT_TAPE_CT_EJECTED" >> TAPES_EJECTED.log
mv TAPES_EJECTED.log TOT_TAPES_EJECTED.rpt.$rdat
}

#--------------------------------------
# M A I N . . .
#--------------------------------------
cat $EJECTED_TAPES
echo "Total Tapes to eject is: "; cat $EJECTED_TAPES | wc -l

echo " Is this the correct list of tapes to eject (y/n)?"
read option
case $option in
y|Y) TAPE_ROUTINE;;
n|N) exit
esac