Mon shell doit interpréter "
Bonjour,
Voila j'ai écris un shell, mais ce dernier doit pouvoir interpréter une double quote => "
voila mon shell :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main ()
{ int i;
char * ligne;
char *tokens[100];
ligne=(char*)malloc(300);
printf("$ ");
fgets(ligne,256,stdin);
while (strcmp(ligne,"exit\n"))
{ i=0;
tokens[i]=strtok(ligne," \n");
while (tokens[i] != NULL) tokens[++i]=strtok(NULL," \n");
if (fork()==0)
{ execvp(tokens[0],tokens);
printf("Commande invalide\n");
exit(1);
}
wait(0);
printf("$ ");
fgets(ligne,256,stdin);
}
exit(0);
} |
Un rappel : Si on tape dans le shell linux echo "a b"
il affiche a b
Grace aux " , le shell prend les espaces .
merci d'avance :)