Question: C help Please... For this assignment you will implement your own Shell or Command Line Interpreter (e.g. to replace /bin/bash for simple interactions with the
C help Please...
For this assignment you will implement your own Shell or Command Line Interpreter (e.g. to replace /bin/bash for simple interactions with the Linux Kernel.). Your shell will be character-oriented, and will fork off processes to execute user commands. Your shell should read lines of user input into a 256-byte buffer, then parse and execute the commands (be sure to clear the buffer between successive commands!) It should be possible for the user to specify the command to execute by giving an absolute path to the file containing the executable (e.g. ./hw1); or to use path expansion to locate the file containing the executable by using the environment PATH variable to construct a series of absolute paths and executing the first file found in this way (note that the execvp() command performs this processing automatically, you do not need to program this yourself!) Your code should parse the input string and separate it into a collection of sub-strings (stored in myargv[]) along with a count of the number of strings encountered (stored in myargc). Note that piped commands will require multiple argc/argv instances!
Your shell should support the following functions:
Execute a single command with up to four command line arguments (including command line arguments with associated flags). For example:
Myshell> ls l Myshell> cat myfile
Myshell> ls al /usr/src/linux
Execute a command in background. For example: Myshell> ls -l &
Myshell> ls al /usr/src/linux &
Redirect the standard output of a command to a file. For example: Myshell> ls -l > outfile
Myshell> ls -l >> outfile
Myshell> ls al /usr/src/linux > outfile2 Myshell> ls al /usr/src/linux >>outfile2
Redirect the standard input of a command to come from a file. For example: Myshell> grep disk < outfile
Myshell> grep linux < outfile2
Execute multiple commands connected by a single shell pipe. For example: Myshell> ls al /usr/src/linux | grep linux
Execute the cd and pwd commands
Myshell> cd some_path
Myshell> pwd
Extra Credit (15 Points): Implement your shell so that any combination of the shell functions above can be used in a single command line.
Extra Credit (10-Points): Implement the shell so the current working directory is shown on the prompt. For example:
OLD PROMPT:
myshell >>
NEW PROMPT:
myshell ~/ >>
myshell ~/hw3 >>
myshell ~/hw3/build >>
Extra Credit(20): Add the functionality to your shell to store a history of all commands typed. This includes the ability to scroll through this history as well and rerun typed commands. See l your basic Linux shell for examples. This also requires the use of the up and down arrow keys to scroll through the list.
#include
#include
#include
#include
#include
#include
#include
//Max amount allowed to read from input
#define BUFFERSIZE 256
//Shell prompt
#define PROMPT "myShell >> "
//sizeof shell prompt
#define PROMPTSIZE sizeof(PROMPT)
int main(int* argc, char** argv)
{
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
