Question: A shell is an interactive command-line interpreter that runs programs on behalf of the user. A shell repeatedly prints a prompt, waits for a command

A shell is an interactive command-line interpreter that runs programs on behalf of the user. A shell repeatedly prints a prompt, waits for a command line on stdin, and then carries out some action, as directed by the contents of the command line. In this assignment, you will write a shell that allows the user to interactively execute Unix programs. Your shell, called New Shell (newsh), reads commands typed by the user and then executes them. It also allows users to set variables that can be used in subsequent commands. You may write newsh in C or C++.

Like other shells, newsh accepts both built-in commands and program-control commands. Commands are constructed out of tokens. A token is string without any space. Tokens are subject to variable substitution, as described below. There can be any amount of empty space before and after tokens. The % symbol introduces a comment, which continues to the end of the line. You may assume that % never appears within a token. newsh ignores all characters in a comment. If a line is empty (or just spaces) except for a comment, it is a valid command that has no effect. 3 Build-in Commands newsh supports following build-in commands: set variable value Here, variable is any reasonable variable name (starting with a letter, continuing with letters or numbers), and value is a token. It is conventional for users to represent variables in ALL CAPITALS, but newsh does not enforce this convention. Variable names are case-sensitive, that is, home and HOME represent different variables. The effect of this command is to associate the name with the value of the variable in a data structure inside newsh. The variable can be referenced later by using $variable. newsh needs to deal with a special case. If variable is PROMPT (without quotation marks), the shell prompt should be changed to value in the command. Add one space at the end of the new prompt. The initial prompt in newsh is newsh$ (There is a space after the $). It will be changed by this command. 1 cd directoryName This command changes the current directory to directoryName. The cd command must have a single parameter. See the getwd(3) and chdir(2) system calls. The directoryName may be either absolute (starting with /) or relative (not starting with /). bp newsh lists all processes running in the background, in any format you like. newsh should keep a list and not rely on external programs like ps to create its output. quit newsh exits with exit status 0. newsh should also accept (end-of-le) on the input stream and treat it as if the user had typed quit. That is, if a user types at the input, newsh performs exactly the same as when it receives the built-in command quit. 4 Program-control commands newsh supprts following program-control commands: cmd param The user submits this command to execute a program. Here, cmd is a token that species the lename of the program the user wants to execute. It is followed by zero or more tokens specifying parameters. newsh should wait for the program to nish before it prompts for and accepts the next command. newsh looks for cmd in a list of directories indicated by the variable PATH, whose value is a colonseparated list of directories. If, however, cmd starts with a / character, it is a full path name starting at the root. Similarly, a cmd that starts with ./ is a path name starting in the current directory. cmd param & This command is identical to the previous one, except that the program should run in the background, that is, newsh should immediately prompt for and accept the next command.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!