Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:37:48+00:00 2026-06-17T20:37:48+00:00

I have #!/bin/sh func1() { echo This is func1 from shell script } func2()

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:37:49+00:00Added an answer on June 17, 2026 at 8:37 pm

    This is unlikely to be a good idea, but I suppose you could write something like this:

    if (! fork()) { // TODO fork can return -1 on error; should check for that
        execl("/bin/sh", "-c", ". FILE && func1", (char *)NULL);
        // TODO should check to make sure execlp successfully replaced the process
    }
    

    where FILE is the name of the .sh file that defines func1. 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 in FILE, and if that succeeds, then run the command func1“).

    For more information:

    • about fork
    • about execl
    • about .
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just installed composer in my /usr/bin folder, so when from that folder
I have a #!/bin/sh script that has the following line: if [ ! -x
I have a file structure that looks like this ./501.res/1.bin ./503.res/1.bin ./503.res/2.bin ./504.res/1.bin and
I have an executable file that can be used from the terminal command line.
I have dlls in bin directory. I can't see where they are referenced in
I have the following PHONY target in Makefile install: echo /usr/bin/shelldecrypt must be writable
I have a table that's created like this: CREATE TABLE bin_test (id INTEGER PRIMARY
My service(TCP) have bin installed in IIS7 before and this is the requirements for
I can't seem to find any good documentation on this. I have a list
I have this C++ 11 code that uses lambda, this is an example. #include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.