1

I am attempting to code and execute bash scripts using C lang. Purpose is for a personal project I'm writing in C, and seeing if I can include bash capabilities as well. I created a simple C file script.c(compiled as script) for testing, but I am getting the error:

bash: ./script: Permission denied

I have tried running with sudo permissions, but still getting similar response:

sudo: unable to execute ./script: Permission denied

All I intend to do with this file is run the bash command: echo "hello" using C

Here is the C file:

#include <stdio.h>
#include <stdlib.h>

#define SHELLSCRIPT "\
        #/bin/bash \n\
        echo \"hello\" \n\
"

int main() {
        puts("executing script");
        system(SHELLSCRIPT);
        return 0;
}

My wild guess is that the line with system(SHELLSCRIPT); is the cause, being that not even a root user can make system calls. However, after looking through the internet consensus is that it is possible to execute bash scripts in this fashion. Any help or insight is apprecitated.

jsfer
  • 11

1 Answers1

0

It appears I didn't properly mount the hard drive I'm working in with correct permissions. So files just won't work outright. This program works when created in a different, correctly mounted, drive.

jsfer
  • 11