Skip to main content

/bin/sh: 0: Can't open sh [Resolved]

I'm trying to run a simple C program.


extern char** environ;

int main(){
//  execl("/bin/sh","sh","-c","/bin/ls -l",(char *) NULL);
    char* argv[] = {"/bin/sh","sh","-c","/bin/ls", (char*) NULL};
    execve(argv[0], argv, environ);
    return 0;

The commented out execl runs fine. But when I try to do the same with execve, then the compiler invokes the following error:

/bin/sh: 0: Can't open sh

What am I doing wrong here?

Question Credit: Robur_131
Question Reference
Asked July 20, 2019
Posted Under: Unix Linux
1 Answers

Your Answer