can a C function return value to Shell Script variable
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
can a C function return value to Shell Script variable
Could you please suggest me how can I do this ?
I want to call a C function from a shell script.
It returns a value.
I want to catch and assign the value returned by the C function to a shall variable and echo it.
Thank you friends esapcially mcnamara and Y0jiMb0, but I don't want the exit status.
I want the value returned by a C function caught into a shell variable.
-------I Want No Temporary Files Involved-----------
Clearly put, I want to use a C function in my script to get some thing complex...
because I know C better than Scripting.
I want the output of C function into my shallscript variable.
I you can do it please mail me the code you tried.
Okay. You cannot embed C code in shell language scripts. Each C module has to be a standalone executable (compiled) binary file.
What you want is something like Perl or Python. These are interpreted languages, not compiled, and if you need to, you can embed custom functions written in an interpreted language inside shell scripts.
If you know C, consider downloading and using Python. It's free.
Thank you friends esapcially mcnamara and Y0jiMb0, but I don't want the exit status.
I want the value returned by a C function caught into a shell variable.
-------I Want No Temporary Files Involved-----------
Clearly put, I want to use a C function in my script to get some thing complex...
because I know C better than Scripting.
I want the output of C function into my shallscript variable.
I you can do it please mail me the code you tried.
1) create a main program for the function.
2) The main function calls the function and prints the result.
3) In the shell script do:
...
Clearly put, I want to use a C function in my script to get some thing complex...
...
Then, for example, learn Perl and, if you still think it's not enough, use Perl 'Inline::C" module - I am using it a lot computationally intensive stuff working in real time.
The person knows C was asking how to connect results to a shell variable. So in 45.57893763 seconds typed in a segment of code to show printing resutls of function and how to use shell script. So now it is a complete working example.
By the way this took less than 1 minute of time.
Last edited by allanf; 01-19-2010 at 09:57 AM.
Reason: show the complete solution rather than an aid to get to the complete solution.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.