Is it possible to call a C function from within a shell script. This C function is part of an API. What do I need to make it work from my shell script. Anybody please help.
sorry but you cant call a C system call fomr within a shell script.
you can call another script or program to do what you need
or even better if a shell command could do it.
but no C function,sorry!
Thank you for your reply.
I was wondering why a shell cannot provide a way of calling a c function. After all, all the commands within the shell have their equivalent C code form and the corresponding exe is run.
So why not shell provide a way out for calling a c function
that I write and include the path in the script.
Please throw some light on this.
Thanks a lot,
If you want to write your own C function , you can compile it as an executable which will get input from command line argument, and then you'll just place its path in the shell script to run it successfully.
but If you ask about refering a non-compiled C function, the shell just won't know how to run it since it isn't build to function as a compiler...
me2unix does a great job of stating the main difference between C program and shell programs.
C is a compiled and executed language.
Shells are C programs written to interpret commands without compiling them.
The same holds true for PERL, PYTHON, PHP and other C programs that are compiled.
So, just look at SHELLs as C programs that have built-in functions and the ability to call other C programs. If you need a C program feature in a SHELL, you simply write a C program, compile it and execute it within the SHELL environment, as me2unix explains.
In fact, entire programs are often written via SHELLS as folks familiar with PHP, PERL, etc. Even the Java Virtual Machine (JVM) is a 'kind of SHELL' program if you think about it. The JVM is just a 'special class of shell'.
This was a good question by the thread starter and a good answer by m2unix.