Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 1- Unix Shell The next task is to modify the shell interface program so that it provides a history feature to allow a user

Project 1- Unix Shell

The next task is to modify the shell interface program so that it provides a history feature to allow a user to execute the most recent command by entering !!. For example, if a user enters the command ls l , she can then execute that command again by entering !! at the prompt. Any command executed in this fashion should be echoed on the user's screen, and the command should also be placed in the history buffer as the next command.

Your program should also manage basic error handling. If there is no recent command in the history, entering !! should result in a message No commands in history.

Can someone help me add the history feature to this code? The program is written in C on a Unix environment. I would really appreciate it. Thank you.

#include #include #include #include #include

#define MAX_LINE 80 /*The maximum length command*/

int main(void) { char *args[MAX_LINE/2+1];/*command line arguments*/ int should_run=1;/*flag todetermine when to exit program*/ while(should_run) { /*Shell promt*/ printf("osh>"); fflush(stdout); char command[MAX_LINE+1]; fgets(command, MAX_LINE+1 , stdin); // read and store command line input if (!strcmp(command,"exit")) should_run = 0; else { pid_t pid; pid = fork(); if (pid == 0) { command[strlen(command)-1] = 0; char *token = strtok(command, " "); int i = 0; while(token!=NULL) { args[i] = token; token = strtok(NULL, " "); i++; } args[i] = NULL; execvp(args[0], args); exit(0); } else { if (command[strlen(command)-2] == '&') continue; else wait(NULL); } } } 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

More Books

Students also viewed these Databases questions

Question

Explain the causes of indiscipline.

Answered: 1 week ago