Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hints and Clues on Assignment 2 The Problem: Write a mini-shell using the templa

ID: 3793966 • Letter: H

Question

Hints and Clues on Assignment 2
The Problem: Write a mini-shell using the template code on Page 55 of MOS. This exercise will give you an idea on how a shell program functions.
As we discussed in class, implementing function type_prompt() can be very straightforward, as simple as one line of printf() or cout code.
Making read_command() work could be a little more involved. The key is to properly prepare the parameters parameter. You can find example program on usage of execve() in its man page (man execve). Note that command contains the first argument, the file name; while parameters contains all information of the input line in an array of strings, including the executable file name, same as in the command, as its first string. Do not forget to initialize a dynamic string before filling it with characters.
Some of the most commonly used commands are built-in command handled by shell, for example, exit. You will not be able to test these commands with your shell unless you implement them within your shell program. Built-in commands is processed by the shell program without invoking the fork-exec() loop.

Can anyone provide the solution for this.

We have to write a shell program similar to fig 1.19 screen shot by adding some features such as redirection of input and output, pipes and background jobs

#define TRUE 1 while TRUE) repeat forever type prompt display prompt on the screen read command (command, parameters), read input from terminal if (fork() 0) fork off child process Parent code. waitpid(-1, &status;, 0); wait for child to exit else Child code. execute command execve (command, parameters, 0); Figure 1-19. A strpped-down shell. Throughout this book, TRUE is assumed to be defined as 1 In the most general case, execve has three parameters: the name of the file to he ever muted nointer to the aroument arrax and n nainter to the An Tirnnment

Explanation / Answer

get_return(){
printf ' Press return '
read x
return 0
}

get_confirm(){
printf ' Are you sure? '
while true
do
read x
case "$x" in
y|yes|Y|Yes|YES)
return 0;;
n|no|N|No|NO)
printf ' cancelled '
return 1;;
*) printf 'Please enter yes or no';;
esac
done
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote