Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement - Design and implement a basic shell interface in C that supports the execution of other programs and a series of built-in functions,

Problem Statement - Design and implement a basic shell interface in C that supports the execution of other programs and a series of built-in functions, as specified below. The shell should be robust (e.g., it should not crash under any circumstance beyond machine failure).

General Shell Structure The shell (command line) is just a program that continually asks for user input, perhaps does something on the users behalf, resets itself, and again asks for user input. Here is an example: while(1) { */ Get user input */ */ Exit? */ */ Do something with input */ }

The Prompt At this point, the prompt should indicate that the shell is ready to accept input from the user. Often times, it also shows useful information, such as the name of the user running the shell and the current directory. For now, you just need to implement a simple prompt. The prompt should look like the following: o prompt$ There should be a space after the dollar sign so that the user input does not visually run into the prompt.

Command Line Parsing Before the shell can begin executing commands, it needs to extract the command name and the arguments into tokens. It might be nice to store these tokens into an array so that you can then parse each one in order. In our shell, the first token will always be the name of the program we wish to execute, and all remaining tokens (perhaps including the first token) will be arguments to that program. The function strtok() will be helpful to do this, but it is a bit tricky to use. Be sure to look at the class notes. Take note of the following assumptions: No leading whitespace One space separates the command line tokens. No trailing whitespace You can assume that each token is no longer than 80 characters. You can assume that a command will have at most 10 space-separated tokens Make sure that you can successfully print out your array of tokens through different iterations of your shell loop before moving on. If you see garbage in any of your commands or arguments, try using the C library call memset() or bzero() to clear out your input string and token array before and/or after you are done using them. The C library call fgets() can gather user input from the screen and save it into a string (C character array). See the man pages for strtok, fgets, memset, or bzero for more information.

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions