I am writing a very basic shell for my school. Even thought commands like "pwd" or "date" works when i try "ls" it shows me that "ls: No such file or directory error"
The code of my shell is bellow:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
int i;
char *line=(char *) malloc(1024*sizeof(char));
while (1) {
/* Print the command prompt */
printf("$ ");
fflush(stdout); /* Anagazei na trexei thn printf
/* Read a command line */
fgets(line, 1024, stdin);
for(i=0;i<1024;i++){
if(line[i]=='\n')
{
line[i]='\0';
}
}
//printf("%s", line);
pid_t pid = fork(); /* Dhmiourgei paidi. antigrafo diergasias. */
if (pid==0){
execlp(line,line);
}
else waitpid(pid,0,0);
}
}
ls
can not be found in the shells working directory. Try using the full path tols
like/bin/ls