Function not found error

Hi All,

I have written one shell script where I should call a function by passing variables to the actual function based on some condition.

Each time I run the script I am getting the below error

dsadm@bunyipd: /var/datastage/FRPDEVL/work/script> sh MClub_Validations.sh
Iteration: 1
MClub_Validations.sh[38]: fn_MClub_Validation:  not found.
Iteration: 2
MClub_Validations.sh[45]: fn_MClub_Validation:  not found.
Iteration: 3
MClub_Validations.sh[52]: fn_MClub_Validation:  not found.
Iteration: 4
MClub_Validations.sh[59]: fn_MClub_Validation:  not found.
Iteration: 5
Successfully completed all Iterations

Below is the code inside the shell script,

#!/usr/bin/sh
#This loop is to call each case block automatically which will perform validations against each file
for i in 1 2 3 4 5;do
	iteration=$i
	echo "Iteration: "$iteration
	value=$iteration
	case $value in
#If Iteration value=1, then perform validation for MClubAnn_*.txt file
	1)
			dir_loc_1=/var/datastage/FRPDEVL/work/source/landing/dsmcbann
			f_name_1=MClubAnn_*.txt
			#Function call
			fn_MClub_Validation $dir_loc_1 $f_name_1
	;;
#If Iteration value=2, then perform validation for MClubQLD_*.txt file
	2)
			dir_loc_2=/var/datastage/FRPDEVL/work/source/landing/dsmcbqld
			f_name_2=MClubQLD_*.txt
			#Function call
			fn_MClub_Validation $dir_loc_2 $f_name_2
	;;
#If Iteration value=3, then perform validation for MClubNSW_*.txt file
	3)
			dir_loc_3=/var/datastage/FRPDEVL/work/source/landing/dsmcbnsw
			f_name_3=MClubNSW_*.txt
			#Function call
			fn_MClub_Validation $dir_loc_3 $f_name_3
	;;
#If Iteration value=4, then perform validation for MClubWA_*.txt file
	4)
			dir_loc_4=/var/datastage/FRPDEVL/work/source/landing/dsmcbwa
			f_name_4=MClubWA_*.txt
			#Function call
			fn_MClub_Validation $dir_loc_4 $f_name_4
	;;
#End of case block
	esac
#As there are only 4 files after 4 loops once the iteration value is 5, exit the job with normal status.
		if [[ $iteration -eq 5 ]]
		then echo "Successfully completed all Iterations"
		exit 0
		fi
#End of main for loop
done

#Function start to perform validation against each file
fn_MClub_Validation()
{
	cd $1
	for fname in $2;do
#Check for files existence in the corresponding directory and perform validation
		if [ -f "$fname" ]
		then
			echo "Expected file(s) found, Performing Validations for file: "$fname
			filename=`basename $fname`
			fdate=`echo $filename|tr -dc '[:digit:]'`
			echo $filename","$fdate
#Validation: Check the header and data record at which line they are ending and starting respectively.
			echo "------------------------------------------------------------------------------------"
			echo "Checking header and data record Validation for File: $filename"
			echo "------------------------------------------------------------------------------------"  
			count=0
			while read line
			do
				count=`expr $count + 1`  
					if [[ $count -eq 6 && $line == "" ]] || [[ $count -eq 6 && [[ $line == "Initials" || $line == "DATE" || $line == "Box No" ]] ]]
					then echo "The data record is not found at Line No: "$count", Please check the file."
					exit 16
					elif [[ $count -eq 7 && $line == "" ]] || [[ $count -eq 7 && $line == "Listing	No" ]]
					then echo "The data record is not found at Line No: "$count", Please check the file."
					exit 16
					fi
			done < $filename
			echo "The file is as expected"
			echo "------------------------------------------------------------------------------------"
			echo "Header and Data Record Validation check for File: $filename completed"
			echo "------------------------------------------------------------------------------------"
		else
			echo "Expected files not found, Hence not performing any validations"
		fi  
	done
}
#Function end

Please help me what is wrong in my function call, Is it a right way to call a function. Please do help me

With Regards,
TPK

The function needs to be defined, before you call it the first time. So put it above the for-loop.