Question
In this assignment, you will implement a shell. The shell should operate in this basic way: when you type in a command (in response to
In this assignment, you will implement a shell. The shell should operate in this basic way: when you type in a command (in response to its prompt), the shell creates a child process that executes the command you entered and then prompts for more user input when it has finished. The shells you implement will be similar to, but simpler than, the one you run every day in Unix. If you don't know what shell you are running, it's probably bash.
Program detail Basic Shell: myshell
Your basic shell, called myshell is basically an interactive loop: it repeatedly prints a prompt myshell> (note the space after the greater-than sign), parses the input, executes the command specified on that line of input, and waits for the command to finish. This is repeated until the user types exit. The name of your final executable should be myshell. The shell can be invoked with either no arguments or a single argument; anything else is an error. Here is the no-argument way:
prompt> ./myshell
myshell> At this point, myshell is running, and ready to accept commands. Type away! The mode above is called interactive mode, and allows the user to type commands directly. The shell also supports a batch mode, which instead reads input from a batch file and executes commands from therein. Here is how you run the shell with a batch file named batch.txt: prompt> ./myshell batch.txt One difference between batch and interactive modes: in interactive mode, a prompt is printed (myshell> ). In batch mode, no prompt should be printed. You should structure your shell such that it creates a process for each new command (the exception are built-in commands, discussed below). Your basic shell should be able to parse a command and run the program corresponding to the command. For example, if the user types ls -la /tmp, your shell should run the program /bin/ls with the given arguments -la and /tmp (how does the shell know to run /bin/ls? It's something called the shell path; more on this below) Your project is to develop/write a simple shell - myshell - that has the following properties: 1. The shell must support the following internal commands:
a. cd
b. clr - Clear the screen.
c. dir
d. environ - List all the environment strings.
e. echo
4. The shell must support I/O - redirection on either or both stdin and/or stdout. That is, the command line programname arg1 arg2 < inputfile > outputfile will execute the program programname with arguments arg1 and arg2, the stdin FILE stream replaced by inputfile and the stdout FILE stream replaced by outputfile. stdout redirection should also be possible for the internal commands dir, environ, echo, & help. With output redirection, if the redirection character is > then the outputfile is created if it does not exist and truncated if it does. If the redirection token is >> then outputfile is created if it does not exist and appended to if it does.
5. The shell must support background execution of programs. An ampersand (&) at the end of the command line indicates that the shell should return to the command line prompt immediately after launching that program.
6. You are to include an implementation of command line pipes. (essentially an extension of redirection) so that commands can be strung together. An example is cat out.txt | wc l
7. The command line prompt must contain the pathname of the current directory.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started