Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create an executable script which is not readable/writable

However since an interpreter needs to read this file it is not possible to do so directly. Therefore I wanted to know if I could explicitly load an interpreter into a C program along with my script.

This would allow me to set the permission of the C program according to my needs.

share|improve this question
Your C wrapper is going to use setuid? If your question is simply about how to call the shell executable from a C program, this sounds more like a question for StackOverflow to me. – depquid Apr 1 '13 at 14:15
up vote 3 down vote accepted

You can call shell scripts from C application using system() function:

system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed. During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.


#include <stdlib.h>

int main(int argc, char *argv[]) {

    char* command = "\
for i in 1 2 3 4 5;\
    do echo \"$i\"; \

    return 0;


$ gcc test.c -o test
$ chmod 100 test
$ ./test

Remember that argument is a command string so you have to terminate lines with semicolons. You also have to escape quotation marks.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.