here is the question:
Your task is to write a simple Unix command-line shell (like bash). Obviously your shell will not be as featureful as bash is. Your shell will be written in C.
Your shell should consist of a loop which:
- Reads in a line of text from the user (e.g., via fgets). You may assume a maximum line length of 100 characters
- Parses that line of text into an array of words
- Using the fork(), execvp() and waitpid() system calls, launches the requested program and waits until the program has finished
In addition to running external programs, your shell must also support 2 builtin commands (commands which are handled by NOT fork()ing and execvp()ing). Those two builtin commands are:
- exit. If the user types in "exit" as a command, your shell should exit (i.e., end the loop)
- cd. If the user types in "cd" followed by another word, your shell should execute the chdir() system call directly. The chdir() system call has not been discussed in class, but you should find sufficient documentation on chdir() by typing in "man chdir" at a Linux command-line or by typing "man chdir" into Google
To determine whether the user has typed in a bulitin command or typed in a command that should be completed by an external program (via fork() and execvp()), use the strcmp function in standard C. The strcmp function will return to you a value of 0 if two strings have the same value, which can be used to determine if the user typed in "exit" or "cd".