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
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