Calling Function in KSH

I have a script with 2 functions
1) show_menu
2) create

Ths show_menu function works fine....... Sort of....

When I select option 2 of the menu the code does a few commands and then calls another function called create. It's at this point that I get "create: not found".....

However, when I move this create function to the top of the script, it seems to work?

menu option 2 below:

2|z|Z)
                #############################################
                #
                # Option 2 bla..bla....
                #             #############################################


echo "\nLooking for a ZFS pool or disks to create a ZFS pool..."
cat <<EOD
        A ZFS pool is needed to store guest domain boot disks.
        The following ZFS pools are available:
EOD
                /usr/sbin/zpool list
        USEZPOOLANSWER=`/usr/bin/ckyorn -p "Would you like to use one of ZFS pools listed for the guest domain boot disk?"`
        if [ "${USEZPOOLANSWER}" = "y" ]
        then
                ZFSPOOLLIST=`/usr/sbin/zpool list -H |\
                /usr/bin/awk '{print $1}'`
                ZFSPOOL=`/usr/bin/ckitem -p "Please select which ZFS pool to use to store the boot disk for this guest domain:" ${ZF
SPOOLLIST}`
                create
        else
                echo "Exiting."
                exit
        fi
#fi
exit
                sleep 5
                show_menu;;

So as you can see from the above code if I move the function create to the top of the script it will work, but if I move the function create to the end of the script I get the "create: not found"...

Thanks for any tips........

Hi.

Is the create function defined after the call to show_menu in your script?

i.e.

OK:

$ cat Test
create() {
  echo In create function
}

show_menu() {
  echo in show_menu function
  create
}

show_menu

$ ./Test
in show_menu function
In create function

OK:

$ cat Test
show_menu() {
  echo in show_menu function
  create
}

create() {
  echo In create function
}

show_menu

$ ./Test
in show_menu function
In create function

Not OK:

$ cat Test
show_menu() {
  echo in show_menu function
  create
}

show_menu

create() {
  echo In create function
}

$ ./Test
in show_menu function
./T: line 4: create: not found

Correct, the create function is declared after the show_menu.

---------- Post updated at 02:34 PM ---------- Previous update was at 02:05 PM ----------

I think you have to delcare the function before it is used........ lol