Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your shell will have a loop that reads command lines and process them. The prompt for your shell will be shell _ jr: .
Your shell will have a loop that reads command lines and process them. The prompt for your shell will be "shelljr: The commands your shell must handle are:
exit When the user enters the exit command the shell will stop executing by calling exit with the exit code Betore executing exit, the shell will print the message "See you".
goodbye Has the same functionality as exit.
cd This command changes the current directory. You can assume the user will always provide a directory as an argument. Assume that a directory name does not include whitespace characters.
pushd This command is used to change the current directory to the directory given as the commandline argument and simultaneously push the current directory onto a stack of directories. Shell Jr can keep directories on the stack. If the user try to push more than print the message "Directory stack is full" and the current directory won't be changed. Assume that a directory name does not include whitespace characters.
dirs This command will print the directories in the stack.
popd This command is used to retrieve the directory from the top of the stack and change the current directory to the directory. It will remove top directory from the stack. If the user try to pop a directory when the stack is empty, print the message "Directory stack is empty" and the current directory won't
be changed.
A command with a maximum of one argument eg wc location.txt That means your shell should be able to handle commands like date or wc location.txt Note that these are not shell commands but executable binaries.
Requirements:
You must NOT use an exec function to implement the functionality associated with the commands exit, goodbye, cd pushd, dirs, and popd. For other commands, you must create a child via fork and use execvp to execute the command.
If the user provides an invalid command, the message "Failed to execute followed by the command name should be printed. In this case the child will exit returning the error code EXOSERR. Use printf to display the message and flush the output buffer eg fflushstdout Note that the shell is not terminated by executing an invalid command.
You don't need to handle the case where the user just types the enter key. That is you can assume the user will always provide a command.
Make sure you use printf to print the shell prompt and that you flush the buffer
Your shell should dynamically create memory space for the directory given for the pushd command and free the space when popd is executed. The directory pushed to the stack should be an absolute path. For example, if the current directory is usr and pushd include is entered, usrinclude will be pushed to the stack.
You must use execvp and no other exec system call
Your code must be written in the file shelljrc
You may not use dup read, write, nor pipes not discussed in class.
You must not use system in order to execute commands.
You can assume a line of input will have a maximum of characters.
Provide a makefile that builds an executable called shelljr Name the target that builds the executable shelljr Feel free to add any additional targets you need.
All your programs in this course should be written using the compiler gcc with the options defined in the gccaliasesinfo.txt file. This file can be found in the info folder of the public grace account.
Common error: If you get the submit server message "Execution error, exit code execute "make clean before submitting your code.
Common error: To forget to return the correct value eg in your code.
Your program representing your shell does not take command line arguments. That is the main function is: int main
When you see that execvp relies on argv that means it uses an array of strings argv is not the parameter associated with command line arguments Just initialize argv with an array of strings and pass it to execvp.
Your shell should exit when end of file is seen. This explains why public tests do not have exit nor goodbye as the last command.
ShellJr exercise relies on Standard IO eg scanf, fprintf, fgets, and so on NOT UNIX IO egwrite or read function not yet discussed in class
ShellJr takes a maximum of two arguments eg wc location.txt You can ignore any other values provided after the second argument. For example, if someone enters wc location.txt bla, the last argument bla will be ignored and the command will be processed successfully ie wc location.txt will be executed
For exit and goodbye you can ignore any values provided after the command just exit the shell
Shell shoudl print error message similar to "Cannot Change to directory
You should start by creating a loop that reads lines and displays them. Then process each command start with exixt and cd
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