Question: Write a simple shell that 1. Accepts and runs the commands ls, dir, help, and whoami, 2. Displays Command not found when any other command

Write a simple shell that 1. Accepts and runs the commands ls, dir, help, and whoami, 2. Displays Command not found when any other command than the above ones is executed, 3. Displays command history when upper arrow key is pressed.

Part of the solution asbelow need to complete the code

#include #include #include

#define BUF 1024 #define ARG 32 /*******************************************************************/

int main (int argc, char ** argv) { char lbuf[BUF]; char * args[ARG]; char ** arg; char * prompt = "THIS IS MY SHELL:" ; // Read input while (!feof(stdin)) { // Get command fputs (prompt, stdout); fflush(stdout); if (fgets(lbuf, BUF, stdin )) { // tokenize the input into args array arg = args; *arg++ = strtok(lbuf," \t"); if (args[0]) { // Add your codes here. HINT: First you need to compare args[0] with internal/external commands. Once comparison is true, then pass the command to system() to execute it. if (!strcmp(args[0],"exit")) { break; } else { } } } } return 0; }

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!