calling a c function from shell


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers calling a c function from shell
# 1  
Old 12-04-2000
Question

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.

# 2  
Old 12-04-2000
PHP you can't

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!

Hezki
# 3  
Old 12-05-2000
Hi me2unix,

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,
sesha
# 4  
Old 12-05-2000
Hi again,

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...

Hezki
# 5  
Old 12-06-2000
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multithreading - Calling user function with xargs in korn shell

I know there are other ways of accomplishing the below task, but the purpose of this thread is to understand the below code. I wanted to use xargs with user defined function in korn shell. Am aware, that I could write custom function into a script and place it in FPATH and then call it in xargs,... (2 Replies)
Discussion started by: luhah
2 Replies

2. Shell Programming and Scripting

Calling Pl/sql function in shell script to modify csv

I need to 1.Open a csv 2.Process the csv i.e. Modify 2 column in the csv. To modify the column the value needs to be passed to a pl/sql function and the return value should be updated For eg: If column 2 E,then E will be passed in database function which will return Employee. 3. Write a... (5 Replies)
Discussion started by: Chinky23
5 Replies

3. Shell Programming and Scripting

Calling a function in cpp file inside shell script

Hi I need to call a function written in a cpp file with arguments inside the shell script..Can anyone help me how to do this:( (1 Reply)
Discussion started by: rkrish
1 Replies

4. Shell Programming and Scripting

Is it possible make the shell read functions 1 by 1 and calling an other function?

Greetings, I m wondering if it's possible do do the following : I have a simple function called "FindMoveDelete" which does the following : FindMoveDelete() { find . -iname "$FILENAME*.ext" -exec mv {} "$PATH/$VAR" \; && find . -maxdepth 1 -type d -iname "$FILENAME*" -exec rm -rf {}... (6 Replies)
Discussion started by: Sekullos
6 Replies

5. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

6. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

7. Shell Programming and Scripting

Calling external function in a shell

hi guys, how r u??? please I need you, help me please. I have a shell, in this shell i have this function and another code lines, this function is getting date one day back. the function is in the same shell (FILE 1) Now I need put this function in another file (FILE 2) and calling... (4 Replies)
Discussion started by: acevallo
4 Replies

8. Shell Programming and Scripting

calling a function in Shell script troubleshooting

Some Code After Some code part is executed the control doesnt go to rvin_doxx_scrt.. and the script exits rvin_doxx_scrt() { Some Code } if (som code) ... (4 Replies)
Discussion started by: ultimatix
4 Replies

9. Shell Programming and Scripting

Calling a C-function froma shell script

Hi, I have searched the forum for the query, But i didnt find an exact answer. I have a script(1.sh) and a c program(sample.c) sample.c contains many function definitions.( run(), find(), add() etc). I want to call functions in sample.c from 1.sh and use the return value in 1.sh... (3 Replies)
Discussion started by: jisha
3 Replies

10. UNIX for Dummies Questions & Answers

calling one function from another shell script

i have a function defined in one ksh (ksh 1) i want to use that function in another ksh (ksh 2) i am using . $<directoryname>/<ksh name> i am calling the function defined in ksh 1 in ksh 2 i want the returnstatus from the above operation but it is not executing the function what i... (1 Reply)
Discussion started by: trichyselva
1 Replies
Login or Register to Ask a Question