cis-lclient06:~/class/nov22>more exec9.c #include #include #include #include #define SIZE 40 int main(void) { char buf[SIZE+1], argv0[SIZE], argv1[SIZE], argv2[SIZE]; int argc, pid; while (1) { pid = fork(); if (pid == 0) { printf("\nbsh->"); if (gets(buf) == (char *) NULL) exit(1); /* GETS IS UNSAFE */ argv0[0] = '\0'; argc = sscanf(buf, "%s %s %s", argv0, argv1, argv2); switch (argc) { case 1: execlp(argv0, argv0, (char *) NULL); break; case 2: execlp(argv0, argv0, argv1, (char *) NULL); break; case 3: execlp(argv0, argv0, argv1, argv2, (char *) NULL); break; } printf("%s: command not found\n", argv0); return; } else { wait(); } } } cis-lclient06:~/class/nov22>gcc exec9.c /tmp/cc0YvKHJ.o: In function `main': exec9.c:(.text+0x3e): warning: the `gets' function is dangerous and should not be used. cis-lclient06:~/class/nov22>./a.out bsh->nano new.c #include main() { printf("How do you like Bob's shell?\n"); } ^X Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ? Y File Name to Write: new.c bsh->gcc new.c bsh->./a.out How do you like Bob's shell? bsh->^C cis-lclient06:~/class/nov22>