Is there anyone help me on this?
If I have a C program (fun1) that normally called by another C as fun1(abc). I would like to know how to call fun1 from a Korn shell script. Thanks ahead.
You would have to turn fun1 into a program with a main(), compile it, then call that compiled program from your Korn shell script. How you turn it into a complete C program depends on what the function does.
For example, if your function just adds two numbers and looks like...
[tt]
int fun1(int a, int b)
{
return (a+b);
}
[/tt]
Then to turn it into a complete program, you would do something like...
[tt]
#include <stdio.h>
int main(int argc, char ** argv)
{
printf("%d", fun1(argv[1], argv[2]) );
exit(0);
}
[/tt]
(Note that there is NO error handling in this example!!!) Compile and link it with your fun1() function. Name the compiled program fun1. Then you can call it from a shell script like...
[tt]
VAR1=23
VAR2=45
ADDEDVAR=`fun1 ${VAR1} ${VAR2}`
[/tt]
This is just a very simple example. How you write the C program to be called from a shell script will vary greatly depending on what the function does!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.