Professional Documents
Culture Documents
Work Shop B
Work Shop B
h>
# include<stdio.h>
# include<string.h>
# include<sys/types.h>
# include<sys/wait.h>
# include<unistd.h>
# include<errno.h>
main()
{
char line [MAXLINE], *words[MAXWORDS], message[MAXLINE];
int stop=0, nwords=0;
int result, pid, status;
while(1)
{
printf ("WS B Shell $ ");
if (NULL == fgets(line , MAXLINE, stdin))
return 0;
// exit if fgets() returns NULL (NULL is returnd on error or when end of file occurs while no characters have been read)
tokenize (line,words,&nwords);
if ((strcmp(words[0],"exit") == 0) && (nwords == 1)) // exit if word exit appears in the input as the first word of a line
return 0;
if (strcmp(words[0],"cd") == 0)
{
result = chdir(words[1]); // chdir changes the current working directory to that specified in path