Shell script not processing if statement properly

Hi I am trying to create a shell script that will

look for a contracthead file first and if the contract head file does not exist on day1 exit script.

Now on day2 if contracthead exists or not run the script uploading files in order
such as contract line then contract contact

so the whole order on day1 is
contracthead
contractline
contractcontact

on day2
if it exists or not run the script like the order above even if files are missing.
Now this is the script i came up with.

basically the if statement for the days block seems not be working
it works determinig day 1 and 2 but it does nto run the script as i want it to.

So far.g if it has a contracthead ont he first day and no days file.
It will upload contract head and go to the else statement and create the days file. It should not do this because the contracthead file exists. If it did not exist then the days file will be created.

Could you tell me where i am going wrong please.

Code:

#!/bin/bash
# DATE varaible is used to archive the files after ftp
DATE=`/bin/date +%Y%m%d%H%M`
# TODIR variable is the target directory for the file on remote system 32x
TOARCHIVEDIR=/home/tibco/tibco/archive
# 32x
TODIR=/home/tibco/tibco/AIS_FTP/test/inbound/Staging
# FROMDIR variable is the source directory of the file on the local system   5x
FROMDIR=/home/tibco/ems/FTP/test/inbound/Staging/FTPComplete
# ARCHDIR variable is the directory file get moved to after tranfer 5x
ARCHDIR=/home/tibco/archive/testFtp2_32X  

pwd=`pwd`
echo $pwd
cd $FROMDIR
STEXT="The following files were received in: /home/tibco/ems/FTP/test/inbound/Staging/FTPComplete \n"
ETEXT="The following files were NOT FOUND in: /home/tibco/ems/FTP/test/inbound/Staging/FTPComplete \n"


########Running Loop########
for file in int_sap_contracthead*.txt 
int_sap_contractline*.txt
int_sap_contractcontact_*.txt

do
	echo $file
	if [ -f $file ]
	then
		#echo " file $file exists"
		STEXT="%10s $STEXT \n $file "
		#echo " $STEXT "
	else
		ETEXT="%10s $ETEXT \n $file "
		#echo " $STEXT "
	fi
done
SUCCESS=`printf "$STEXT " `
FAIL=`printf "$ETEXT " `



##################### Checkign if the days file exists######################

NF=Contracthead file not found
NFEMAIL=Contracthead file not found

if [ -e "days" ]
   then
       echo "*** The days file exists ***"
       rm days
       echo "*** removing the days file ***"


       echo " ------ This is day 2 - all files are loading ------ "\n\n\n
    ################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contracthead_*.txt

bye
EOF
############  END FTP ###############       
     echo "*** -- UPLOADING FILE CONTRACTHEAD -- ***"
sleep 8
           elif [ -e "int_sap_contracthead_*.txt" ]
              then
             echo "*** -- UPLOADING FTP -- ***"
################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contracthead_*.txt

bye
EOF
############  END FTP ###############
                  echo "int_sap_contracthead_*.txt File is uploading"   
           
                  else
                      echo "1" > days
                      echo "Files will not upload today"  
                      exit           
fi

sleep 8
##################### End##################

echo "code still running"

if [ "$file" = "int_sap_contractline*.txt" ]
   then
      ################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contractline_*.txt

bye
EOF
############  END FTP ###############
      echo "contracthead File is uploading"  
sleep 8
else 
echo "there is NO contractcontact File to upload"  
fi


if [ "$file" = "int_sap_contractcontact*.txt" ]
   then
       ################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contractcontact_*.txt

bye
EOF
############  END FTP ############### 
      echo "contractcontact File is uploading"   

else echo "there is NO contractcontact File to upload"
fi



HEADER="FTP Summary of the files "
	
mail -s "$HEADER" test@domain.com <<EOF
$SUCCESS
	$FAIL
EOF

# create the archive directory based on timestamp and move files
cd $ARCHDIR
mkdir $DATE
mv $FROMDIR/int_sap_contractline_*.txt $ARCHDIR/$DATE/
mv $FROMDIR/int_sap_contractcontact $ARCHDIR/$DATE/
mv $FROMDIR/int_sap_contracthead_*.txt $ARCHDIR/$DATE/
exit 

elif [ -e "int_sap_contracthead_*.txt" ]

You are testing for the existence of a file with an asterisk truly in the filename. Removing the quotes will make it work provided there is exactly one matching file name.

elif ls int_sap_contracthead_*.txt >/dev/null 2>&1
will work with many names.

if [ "$file" = "int_sap_contractline*.txt" ]
also not gonna fly. Double brackets would work if you unquote the pattern. Or use a case statement.

Hi Perderabo

Thank you very much that did work by removing the quotes. I am a newbie doing this. So I appreciate all the help you gave me.