Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

What roles have these individuals played in your life?

Answered: 1 week ago