Question: Can someone please help me write a shell called Newsh in C or C++.The task is to write a shell called Newsh that reads commands

Can someone please help me write a shell called Newsh in C or C++.The task is to write a shell called Newsh that reads commands typed by the user and executes them. It also allow users to set variables that can be used in subsequent commands. The commands are constructed out of tokens, a token being a string without any spaces, but can have any amount of empty space before and after the token. The % symbol introduces a comment, which contines to the end of the line. Newsh should ignore all characters in a comment. Note: If a command is an empty line or just spaces then it is valid command with no effect.

Newsh must support the following Build-in commmands:

1) set variable value, where variable is simply any variable name and value is a token. 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 $variable.

2) cd directoryName, this command would change the current directory to "directoryName". The cd command must have a single parameter. The directory name (directoryName) can either be absolute (starting with /) or relative (not starting with /)

3) bp, newsh lists all processes running in the background, in any format. Newshel should keep a list and not rely on external programs like ps to create it output.

4) quit, simply exit the program if the user types in "quit" or (end of file) on the input stream and should treat it the same as typing "quit".

Newsh must suppoer the following program-control commands too:

1) cmd param* , cmd is a toke that specifies the filename of the program the user wants to execute. It is followed by zero or more tokens. Newsh should wait for the program to finish before prompting and accepting the next command. If I'm not mistaken Newsh should look for cmd in a list of directories indicated by the "variable" from (1), who's value is colon-seperated list of directories. If cmd starts with a "/" character, it is a full path name starting at the root. If cmd starts with a "./" then it is starting in the current directory.

2) cmd param*&, same thing a the above excpet this one must run in the background and immeditely prompt for and accept the next command.

Overiew: Write procedures that will read from a line from stdin, break the lines into tokens, analyze line for correctness ( only build-in commands). If user enters any command than the ones mentioned then print an error message (to stderr) and prompt for the next command. Newsh should use fork() and exec() (and its variants) to start a process and execute the command on the command line. Cannot use Unix system() library routine to execute the command line.

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!