Error in functions : file2: function: not found

Hi

I had written the small script for calling a function.

bash-2.03$ more file2
function sai
{
echo " this is an example"
}
echo "This is main program"
echo "calling the function"
sai()

when executing the above script. I am getting error.

bash-2.03$ sh file2
file2: function: not found
this is an example
This is main program
calling the function

And the Order of execution is also not correct.

Can any one please help me.

Firstly, declare the script to be a bash script

put this at the start of the script...

#!/bin/bash

bash-2.05$ sh
$ function sai
function: not found

function is not implemented by /bin/sh

bash-2.05$ function sai
> {
> echo hello
> }
bash-2.05$
bash-2.05$ sai
hello

Thanks it is working now