Question

In: Computer Science

In this assignment you will write your own shell program, Mav shell (msh), similar to bourne...

In this assignment you will write your own shell program, Mav shell (msh), similar to
bourne shell (bash), c-shell (csh), or korn shell (ksh). It will accept commands, fork a child
process and execute those commands. The shell, like csh or bash, will run and accept
commands until the user exits the shell.

Your file must be named msh.c


Functional Requirements
Requirement 1: Your program will print out a prompt of msh> when it is ready to
accept input. It must read a line of input and, if the command given is a supported shell
command, it shall execute the command and display the output of the command.


Requirement 2: If the command is not supported your shell shall print the invalid
command followed by “: Command not found.”


Requirement 3: If the command option is an invalid option then your shell shall print
the command followed by “: invalid option --” and the option that was invalid as
well as a prompt to try —help. exec() outputs this automatically make sure you
pass it on to your user. You have no work for this requirement. It’s free.


Requirement 4: After each command completes, your program shall print the msh>
prompt and accept another line of input.


Requirement 5: Your shell will exit with status zero if the command is “quit” or “exit”.


Requirement 6: If the user types a blank line, your shell will, quietly and with no other
output, print another prompt and accept a new line of input.


Requirement 7: Your version of Mav shell shall support up to 10 command line
parameters in addition to the command.


Requirement 8: Your shell shall support and execute any command entered. Any
command in /bin, /usr/bin/, /usr/local/bin/ and the current working directory
is to be considered valid for testing.
Your shell shall search in the following PATH order:
1. Current working directory,
2. /usr/local/bin
3. /usr/bin
4. /bin
Parameters may also be combined. For example, ps may be executed as: ps –aef or ps
–a –e -f


Requirement 9: Mav shell shall be implemented using fork(), wait() and one of the
exec family of functions.
Your Mav shell shall not use system(). Use of system() will result in a grade of 0.


Requirement 10: Your shell shall support the cd command to change directories. Your
shell must handle cd ..


Requirement 11: Your shell shall support the showpids command to list the PIDs of
the last 15 processes spawned by your shell. If there have been less than 15 processes
spawned then it shall print only those process PIDs


Requirement 12: Your shell shall support the history command which will list the last
15 commands entered by the user. Typing !n, where n is a number between 1 and 15 will
result in your shell re-running the nth command. If the nth command does not exist then
your shell will state “Command not in history.”. The output shall be a list of
numbers 1 through n and their commands, each on a separate line, single spaced.
If there are less than 15 commands in the history only list the commands the user has
entered up to that point.


Requirement 14: Tabs or spaces shall be used to indent the code. Your code must use
one or the other. All indentation must be consistent.


Requirement 15: No line of code shall exceed 100 characters.


Requirement 16: Each source code file shall have the following header filled out:


Requirement 17: All code must be well commented. This means descriptive comments
that tell the intent of the code, not just what the code is executing.
The following are poor comments.
The following explains the intent:
When in doubt over comment your code.


Requirement 18: Keep your curly brace placement consistent. If you place curly braces
on a new line , always place curly braces on a new end. Don’t mix end line brace
placement with new line brace placement.


Requirement 19: Each function should have a header that describes its name, any
parameters expected any return values, as well as a description of what the function does.


Requirement 20: Remove all extraneous debug output before submission. The only
output shall be the output of the commands entered or the shell prompt.


Administrative
This assignment must be coded in C. Any other language will result in 0 points.

Solutions

Expert Solution

Theoretically,all shell statements and UNIX commands can be entered in the command line it self.When a group of command has to executed regularly ,they are better stored in a file.all such files are shell scripts,shell programs or shell procedures.shell script can be defined as a group of commands executed in sequence.let's start by describing the steps needed to write and execute a shell script:

step 1: open the file using an editor(e.g.,"vi" or"pico")

ex: $vi firstshellscript.sh.

shell scripts:  A UNIX shell is a command language interpreter,the primary purpose of which is to translate command lines typed at a terminal into system actions. the shell itself is a program through which other programs are invoked.there are several different unix shells,among them the cshell(csh),the bourne shell and the korn shell.

one of the oldest shell is the bourne shell.in most unix machines it is available either in its original form.an improvement over the bourne shell was the korn shell.the bourn shell is primary shell.it has all the primary capabilities.

The following unix command tells us which is our current shell environment: echo $SHELL

for example are shell scripting programming,

#!/bin/sh

echo "enter the limit"

read lim

first=0

second=1

echo "Fibonacci series"

echo "$first"

echo "$second"

for((i=0;I<lim;i++))

do

third=$(($first+$second))

echo "$third"

first=$second

second=$third

done

output:

enter the limit 10

Fibonacci series

0

1

1

2

3

5

8

13

21

34

55

89

/bin :common programs,shared by the system ,the system administrator and the users.

bourne shell: The bourne shell is one of a number of unix shell.it is both a command language and a programming language.

#!/bin/sh

# usage:fsplit file1 file2

total=0;lost=0

while read next

do

totl='expr $total+1

case "$next" in

*[A-Za-z]*) echo "$next">> $1;;

*[0-9]") echo"$next">>$2 ;;

*) lost=expr $ lost +1

esac

done

echo "$total lines read ,$lost thrown aay"

Cshell:The cshell has three separates file which are used for customizing its environment.these three files are chrc,login, and logout.

#!/bin/csh

if($#argv==0)then

echo "no number to classify"

else if ($#argv>0)then

set number =$argv[1]

if($ number<0)then

@ class=0

else if (0<=$ number && $number <100)then

@class=1

else if (100<=$number && $number <200)then

@class=2

else

@class=3

end if

echo the number $number is in class $class

end if


Related Solutions

This assignment will ask you to look at your own finances. For this assignment, write a...
This assignment will ask you to look at your own finances. For this assignment, write a paragraph showing your percentages. I DO NOT want to know how much money you spend or have as income, I am only looking at the percentages. Describe for me what the effect of inflation is on you personally given what you found out. Look at a typical month of your expenditures and income. Create a list of your expenses by category (see below). Create...
Name your source code file sh.c Write your own simple shell. Your shell should prompt the...
Name your source code file sh.c Write your own simple shell. Your shell should prompt the user for a command, run it, then prompt the user for their next command. If the user types "exit", then the shell should terminate. The shell should ignore Ctrl-C. Inside the attached parse.h header file, there is a parse function that you can use to split up the command line into separate strings. Recall that execvp accepts two arguments: the name of the command,...
For this assignment, you are required to write a MIPS program that reads its own instructions...
For this assignment, you are required to write a MIPS program that reads its own instructions and counts the number of occurrences of each type of instruction (R-type, I-type, or J-type). To accomplish this task, your program should execute the following steps: First, your program should load the address of its first instruction (0x400000) into a register, and initialize three separate instruction class counters to zero. Next, your program should enter a loop that reads each instruction from memory. For...
Using C Write a program that will serve as a simple shell. This shell will execute...
Using C Write a program that will serve as a simple shell. This shell will execute an infinite for loop. In each iteration of the loop, the user will be presented with a prompt. When the user enters a command, the shell will tokenize the command, create a child process to execute it and wait for the child process to be over. If the user enters an invalid command, the shell should recognize the situation and show a meaningful message....
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell script to take a directory as an argument and display the contents of that directory (10pts) Write a shell script that takes any command as a parameter and displays help on that command (e.g. the result of the execution of man <command>). (10pts) Write a shell script that requires two file names as parameters and copies content of one file into another without asking...
Writing your own shell in Linux with execvp Only code void cmdToArray() Program should be able...
Writing your own shell in Linux with execvp Only code void cmdToArray() Program should be able to execute ls -l. #include <stdio.h> #include <string,h>// strcmp #include <stdlib.h>// exit #include <unistd.h>// fork, exec #include <sys/wait.h>// wait #define MAXARGS 20 #define ARGLEN 256 void execute(char *cmd, char *arglist[]); void cmdToArray(char *cmd, char *arglist); int main(void) { int pid; char *arglist[MAXARGS+1]; // array of pointers char cmd[ARGLEN]; // read stuff here while (1) { printf("cmd> "); fgets(cmd, ARGLEN, stdin); // remove newline from...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
Design a shell program to remove all the shell programming files ending with sh on your...
Design a shell program to remove all the shell programming files ending with sh on your home directory when a SIGINT signal is received.
For this week’s lab assignment, you will write a program called lab9.c. You will write a...
For this week’s lab assignment, you will write a program called lab9.c. You will write a program so that it contains two functions, one for each conversion. The program will work the same way and will produce the same exact output. The two prototypes should be the following: int btod(int size, char inputBin[size]); int dtob(int inputDec); The algorithm for the main() function should be the following: 1. Declare needed variables 2. Prompt user to enter a binary number 3. Use...
In this assignment you will write a program that encrypts a text file.  You will use the...
In this assignment you will write a program that encrypts a text file.  You will use the following encryption scheme. Ask the user for the name of the original file. Ask the user for the name of the output file. Ask the user for the encryption key, n. Read n2 characters from the file into the n rows and n columns of a 2-dimensional array. Transpose the array.  (Exchange the rows and columns.) Write the characters from the array to an output...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT