Hi, i want to make a little command line shell that executes programs with any required arguments.
But i dont understand what is the problem, why the program donīt work.
Code:
main() {
char cmd[20];
char s[20];
int pid,i,status;
while(1) {
printf("Console$: ");
fgets(cmd,sizeof(cmd),stdin);
for(i=0; i<strlen(cmd); i++) {
if(cmd[i]!=' ')
strcpy(s,cmd);
if(strcmp(s , "exit")==0) {
printf("Shell Terminate\n");
break;
}
}
pid = fork();
if(pid==0)
execv(s,NULL);
else
wait(&status);
}
}