Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
2 Introduction
In this assignment, you are going to implement a mini-shell, namely, asg1-shell, using C.
If one invokes the program asg1-shell, we shall see something like this:
Figure 1: Your shell
The prompt has the format of [3150 Shell:<current directory>]=>. Your shell shall
support:
Execution of any Linux built-in command (e.g., ls).
Five shell-specific commands: gofolder, push, pop, dirs and bye.
Basic signal handling: i.e., a user cannot exit the shell simply by typing ctrl-c.
Basic command chaining: && and k.
Basic error handling.
2.1 Execution of any Linux program
Your shell shall allow a user to execute any Linux program, with basic error handling. Note
that the user can input either an absolute path (e.g., /bin/ls) or just a filename (e.g.,
ls). If an absolute path is not given, your shell should search the program in the following
sequence:
3
/bin → /usr/bin → . (current directory)
In case your shell cannot locate the program, your shell should report an error message
“{command name}: command not found” (see Figure below).
*
2.2 Shell-specific commands
2.2.1 gofolder
This command is similar to cd command in Linux, for changing the working directory, like
below:
4
After a successful operation, your prompt shall be updated with current directory name.
Please note that you are just required to implement basic changing of directory as shown
above.
2.2.2 push,pop and dirs
These commands behave similarly to Linux commands pushd, popd, and dirs.
On push [directory path], the shell shall (1) push the current directory to a stack,
(2) change to the directory specified by [directory path], and (3) print the content
of the stack.
On dirs, the shell shall print the content of the stack. The format is:
[item number] [path]
With the most recent item starts with item number 0 and the oldest item in the stack
has the largest item number.
On pop, the shell shall (1) pop an item from the stack, (2) change to that directory
and (3) print the content of the stack.
If the end of the stack is reached, the shell should prompt the user:
pop: directory stack empty
Example:
5
2.2.3 bye
This command is equivalent to exit command in Linux, which lets a user to terminate the
shell (and back to the normal Linux bash shell).
2.3 Basic signal handling
Your shell shall handle the following list of signals as follow:
Signal Action
SIGINT (Ctrl + C) Ignore the signal.
SIGTERM (default signal of command “kill”) Ignore the signal.
SIGQUIT (Ctrl + \) Ignore the signal.
SIGTSTP (Ctrl + Z) Ignore the signal.
6
2.4 Basic command chaining
Your shell should handle two logical operations: AND(&&) and OR(k), like below:
7
3 The Assignment Package
You should have opened a Github account and told us your github account by filling up a
Google form during your assignment 0. So, after logging in your Github account, come here
https://classroom.github.com/a/KKQgMaHn to get a new repo for this assignment. The
new repo should contain the starter package for this assignment.
4 Your assignment
You are given the following files:
Name Description
/asg1-shell.c Source code of a runnable but non-functioning shell
(Work on it).
/asg1-shell Executable of a runnable but non-functioning shell.
(Try to run it; Type ctrl-d to quit)
/demo-asg1 Executable, serve as the demo of what you shall
implement. Our grading will also use this to define
test cases. That is, the behavior of your shell shall
exactly follow this demo.
/hello Executable, a hello world program.
/testcases/data Test data.
/Makefile Makefile to compile asg1-shell.
/grader.sh We will run this script to grade your assignment
(Don’t touch).
8
4.1 To begin
Make, then run grader.sh, you shall see something like this:
This shell script feeds in some test cases to asg1-shell (barely functioning, but you
should make it functioning in this assignment) and demo-asg1 (which is functioning, but no
source code is given) to match their outputs, and reports the number of test cases passed.
Initially, it shall report that none of the test cases passes. Your job is to make all test cases
pass:
If you invoke the grader script like the following:
./grader.sh 2
Then it only runs test case 2 for you.
9
4.2 Submitting your assignment
Follow the procedure in assignment 0.