Topic: A Simple Shell
Due on or before:
(To be announced)
Maximum Marks: 8
The Simple shell: the behaviour of the simple shell is simply an
- Using system calls to handle all file operations, write a
program in C/C++/Java that copies a file from one location to
another, and deletes the original version. The program should
take two file names as its arguments, the first one being the
file to copy, and the second being the new location. The new
location should not be over-written if it already exists.
The program should check for bad inputs and should work for files
of arbitrary size. In addition, the program should gracefully
handle error conditions while copying the file. Make sure to use
system calls (e.g.,
open) and not the C library for manipulating
- Write a program in C/C++/Java to create files of 1, 10 and
100MB in size, and them time how long it takes to copy these files.
Are the results what you imagine them to be?
Displaying a prompt to indicate that it is ready to accept the
next command from the user
Reading a line of keyboard input as a command, and
Spawning and having a new process execute as per the user's command
Write a simple shell in C/C++. The shell should read a line from
the standard input, parse the line to get the command and its
exec the command.
The shell should wait for
commands to finish, and should exit when it receives the command
exit. When executing a command, the shell should first look for
the command in the current directory, and if not found, search
the directories defined in a special variable, path. Some
general-purpose commands such as ls or installed software have
their executables stores in folder
/usr/bin. The shell should not
be able to run these commands, and report an error till
has been added to the path.
system() command is not allowed, as it simply
invokes the system's
/bin/sh shell to do the work.
You may assume that the command line arguments are separated by whitespaces.
Do not do anything special for backslashes, quotes, ampersands or
other characters that are ``special'' in other shells. Note that
this means that commands in your shell will not be able to
operate on filenames with spaces in them!
You may set a reasonable maximum on the number of command line
arguments, but the shell should handle input lines of any length.
- The executable file for your shell should be named
When executing it, make sure you are executing your own
sh and not
A few shell commands are not separate programs, but are handled
directly by the shell program. You have already implemented
Some convenient built-ins present in many shells are
exit, which is an example of such a command. Now,
cd, the change directory commands. You
will need to invoke the
chdir system call to do
this. Note that if the call to
chdir fails, you
probably don't want to exit the shell, but instead, should handle
the error appropriately.
Implement these in your shell. Do not assume any limit on the
number of times these may be given by a user, in a session.
pushd works like
cd, but pushes the
directory you switched from onto a stack
popd pops the top directory off the stack, and
cds to it. In other words, a
followed by a
popd should bring you back to the
directory you were in, before the
dirs prints the contents of the stack.
The path variable holds a list of possible paths in which
to search for executables. The list of paths is empty by default,
but may grow to any arbitrary size. You should implement a built-in
command to control this variable:
path [+|- /some/dir]
path (without arguments) displays all entries in the
list separated by colons e.g.,
path + /some/dir appends the given pathname to the
path - /some/dir removes the given pathname from the
A shell or a command interpreter, is one of the most important
parts of an Operating System. It is the job of the shell to parse
user inputs, and if required, spawn other processes (which
necessitates the use of the
exec family of
instructions, for any Operating System. UNIX has a large number
of shells, the Bourne Shell
sh, the Bourne-Again
bash, the C Shell
ash, the Korn Shell
and others. For Windows, it is the command interpreter
The login shell is listed in the login record, so that /bin/login
(the program that prompts for the password), knows what shell to
start in, when a login happens. This assignment considers the
design of a simple shell, from scratch.
You may have heard of the limmerick,
There was a Unix salesperson named Eleanor
Who loved her work, but loved the beach more
She found a good way
To combine work and play
She sells C Shells by the seashore
(Schedule: to be announced over email)
Sumantra Dutta Roy
Department of Electrical Engineering, IIT Delhi, Hauz Khas,
New Delhi - 110 016, INDIA. firstname.lastname@example.org