Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

LO2 Distinguish among three types of performance information.

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago