I have
#!/bin/sh
func1()
{
echo "This is func1 from shell script"
}
func2()
{
echo "This is func2 from shell script"
}
I want to call func1 and func2 from a C program. Can I do that ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is unlikely to be a good idea, but I suppose you could write something like this:
where
FILEis the name of the.shfile that definesfunc1. The above will spawn a child process, and replace that child process with an instance of Bash (or whatever your shell is) with the arguments-c(meaning “the script to run is the next argument”) and. FILE && func1(which is the script; it means “run the commands inFILE, and if that succeeds, then run the commandfunc1“).For more information:
forkexecl.