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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MilleniumaireConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
All Courses

From novice to tech pro — start learning today.