Problem with print command

Hi,
I have a small script and am having problem at one point. The script runs another script called Run_SQL.sh. All I am trying to do is if the return code from the script is not zero(0) then display some message(which is working fine) and if the return code is zero then run the SED command and run the print command below it.(see in RED BOLD below). My SED command executes fine but the print command sometime works and sometime does not work. Its sporadic. I know there is something very simple but am not able to figure out.

Any advice will be appreciated.

SQLDIR=$t_path
SQLLISTFILE=${t_path}/$SQLFILE

for SQLNAME in `cat $SQLLISTFILE`
do
SQLFILENAME=${SQLDIR}/${SQLNAME}
print "Running ${SQLNAME}"

Run_SQL.sh -f $SQLNAME
if [ $? -ne 0 ]
then
print "There is error in ${SQLNAME}. Check the file."
exit -1
else
var=`head -1 ${SQLLISTFILE}`
if [ "$var" == "$SQLNAME" ] then
sed '1d' ${SQLLISTFILE} | tee ${SQLLISTFILE} > /dev/null 2>&1 --->This command executes fine
print "${SQLNAME} ran sucessfully" --->This is where I am having problems. This command sometime displays and sometime does not displays text.
fi

fi

The command in bold above run sucessfully and sometime it does not show up at all even if the sed command is sucessful. I have to run this print command after the sed command only.

I will really appreciate any advice in this regard.

sed '1d' ${SQLLISTFILE} | tee ${SQLLISTFILE} > /dev/null 2>&1 --->This command executes fine.
:eek: :eek: :eek:
Never write code soon after you look at one of M C Escher's drawings! You are reading from and writing to the same file from different sides of the same pipeline. OK, that almost makes sense... But the whole purpose of tee is to duplicate an I/O stream. You're keeping the duplicate and sending the original to /dev/null?! Umm...you wanted a fresh copy? Anyway you are going to get different results depending on a lot of factors. You need your sed process to completely read the file prior to the tee process opening the file. That might happen every now and then if the file is short enough.

Hi,
I am sorry, I could not able to understand.
The file I am reading has bunch of sql filenames. Something like:

test1.sql
test2.sql
test3.sql
test4.sql

All I am trying to do is to delete the first line from the file on each iteration of the loop and refresh the file, so that the I can read the next sql filename.

Is there an example I can see in how to fix this.

Will appreciate any help on this.

Thanks