Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

********************* NEEDS TO BE WROTE IN C++******************************** I

ID: 667449 • Letter: #

Question

********************* NEEDS TO BE WROTE IN C++********************************

Introduction:   Building your Own Linux-Shell

The shell or command line interpreter is the fundamental user interface to an operating system, each interactive user can send commands to the OS and by which the OS can respond to the user. The command line is a sequence of ASCII text words delimited by whitespace. The first word in the command line is either the name of a built-in command or the pathname of an executable file. The remaining words are command-line arguments. If the first word is a built-in command, the shell immediately executes the command in the current process. Otherwise, the word is assumed to be the pathname of an executable program. In this case, the shell forks a child process, then loads and runs the program in the context of the child. The child processes created as a result of interpreting a single command line are known collectively.

The new shell should supports:

user commands, such as ls ,date,ls –l –a,

commands with I/O re-direction ,ex : ls –l > a.txt

commands with a single pipe ,ex : who | wc –l

Like all Linux shells, your shell executes a loop. It

prints the shell prompt,

reads the command line (terminated with NULL)

Parses the command line and create its arguments.

Explanation / Answer

#include <iostream>
using namespace std;

string in = {"cat", "cd", "cp", "dd", "df", "ls", "rm", "mkdir", "find", "kill"};

bool inbuilt(string s){
   for (int i = 0; i < 10; i++){
       if(in[i] == i) return true;
   }
   return false;
}

int main(int argc, char* argv[]) {
   if (argc == 0) return 0;
   if (inbuilt(argv[0]) == true){
       // Perform inbuilt OS command;
       using argv[1], argv[2]... upto argv[argc]
   }
   return 0;
}