function error in korn shell

I have sqlldr statements in a function.

These statements are working well and data is being loaded into the tables.

However, i get this error message function:not found.

why?

#!/bin/ksh

function load_abc
{
sqlldr $db_login DIRECT=TRUE CONTROL=$cur_dir/abc.ctl DATA=abc.dat LOG=abc.log BAD=CALLHIST.bad DISCARD=abc.dsc
}

function load_def
{
sqlldr $db_login DIRECT=TRUE CONTROL=$cur_dir/def.ctl DATA=def.dat LOG=def.log BAD=def.bad DISCARD=def.dsc
}

echo "loading abc..."
load_abc

echo "loading def..."
load_def

#> sh run.ksh
run.ksh: function: not found
run.ksh: function: not found
loading abc...
run.ksh: abc: not found
loading def...
run.ksh: def: not found

gram77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gram77Author Commented:
loading abc...
run.ksh: laod_abc: not found
loading def...
run.ksh: load_def: not found
0
set256Commented:
gram77,

I sometimes get my shells mixed up but could the problem possibly be:

function load_abc
{ ...

should it be:

function load_abc ()
{ ...

regards,

seth
0
MilleniumaireCommented:
Hi,

The errors you are getting suggest that the run.ksh script is being run in the bourne shell rather than the korn shell as you require.

The first two error messages are related to the definition of the two functions suggesting that the keyword "function" isn't being recognised:
run.ksh: function: not found
run.ksh: function: not found

The remaining errors are therefore due to the "commands" load_abc and load_def not existing. Obviously if the functions aren't defined, then unix will look for commands with this name.

The #!/bin/ksh entry at the beginning of the script should force the korn shell to be used but this doesn't appear to be the case.  I'm guessing you are running the script from the bourne shell.

I'm not sure exactly what is going wrong here but can you post the results of the following:

echo $SHELL
ps
which ksh

On my system (HP-UX), the ksh executable resides in the /usr/bin directory, not the /bin directory so I would use:

#!/usr/bin/ksh

rather than

#!/bin/ksh

as you have done.  Is it possible that your ksh is located in /usr/bin/ksh also?

I also notice you run the script using "sh run.ksh".  What happens if you run it using "ksh run.ksh"?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

MilleniumaireCommented:
Hi, just wondered if you had managed to fix your unix problem?
0
gram77Author Commented:
Not yet Millenlumaire:
I'll see it tomorrow.

Thanks for the concern
0
gram77Author Commented:
echo $SHELL gives /bin/ksh
ps gives /bin/ksh
which ksh gives /usr/bin/ksh

The function was recognized when I used ksh run.ksh to invoke the function
0
MilleniumaireCommented:
Hi,
The problem is therefore that the first line of your script:
#!/bin/ksh
isn't finding the korne shell as it is located elsewhere.  Try changing this to:
#!/usr/bin/ksh
and the script should now run okay.
I'm sure you are aware, but if you change the privileges of the script you won't need to specify the shell when running it.  Try the following:
$ chmod 755 run.ksh
You should now be able to run the script typing:
$ run.ksh
rather than
$ ksh run.ksh
0
gram77Author Commented:
even after specifying: #!/usr/bin/ksh
Program could not validate the function call and was throwing the error.

The only way the error went was once I invoked the script using ksh run.ksh.

That seemed strange.
0
MilleniumaireCommented:
I agree, that does seem strange.  Is it possible you omitted the ! from the line, something I have done in the past!  You seem quite thorough so I suspect not.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.