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
#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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started