Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: How to call unix shell scripts from 'C'?
Unix shell scripts are interpreted by a program, typically either a command shell (C-shell, bash, sh, tcsh, etc.) or by a scripting language program (perl, python, ruby, etc.)
For a shell script to be "executed" from a shell's command
line, the shell script needs to have the execute bit set
(see man page for chmod(1)) and the first line in the script
will be in the form of:
#!/bin/sh
The important thing is the "#!" token which tells the shell
which interpreter is appropriate for executing the script;
in the example above, the intepreter is /bin/sh.
So, in answer to your question, your C program should optionally check for the execute bit, fopen() the file and perform a fgets() to read a line, the C program should then parse the line to make sure that it conforms to the "#!" convention. If it finds a path to an interpreter, then your C program will probably need to fork() itself, and then use one of the exec() variants, passing it the file path to the interpreter as the name of the program to execute, and also handing it the path to the script as a "command-line" argument. Read the man pages for the particular interpreter to determine if there are any special switches that will have to be passed in order to introduce a script name for the interpreter to automatically run and exit instead of going into interactive mode. If any such switches are needed, you will have to pack it into the exec() call as well.
-----Original Message-----
Sent: Wednesday, October 22, 2003 11:45 AM
To: Multiple recipients of list ORACLE-L
The unix and C forums are pretty inactive. Hope its ok to ask this here.
Anyone know how to do this?
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Rudy Zung INET: rzung_at_printcafe.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-LReceived on Wed Oct 22 2003 - 11:54:42 CDT
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).