All homework submissions are to be made via Git. You must submit a detailed list of references as part your homework submission indicating clearly what sources you referenced for each homework problem. You do not need to cite the course textbooks and instructional staff. All other sources must be cited.
The Git repository you will use can be cloned using git clone gitosis@os1.cs.columbia.edu:UNI/hmwk1.git (Replace UNI with your own UNI). A public/private SSH key-pair will be emailed to you which you will use to access the Git server. Be aware that commits pushed after the deadline will not be considered. Refer to the homework policy section on the class web site for further details.
For all programming problems you will be required to submit source code, a README file documenting your files and code, and a test run of your programs. The README should explain any way in which your solution differs from what was assigned, and any assumptions you made. Refer to the homework submission page on the class web site for additional submission instructions.
Simple Shell (60 Pts.) Even the shell itself is just another user program. The files /bin/sh, /bin/bash, and /bin/tcsh are all executable files for shells. The only thing special about your login shell is that it is listed in your login record so that /bin/login (the program that prompts you for your password) knows what program to start when you log in. If you run ``ypmatch id passwd'', replacing id with your user ID, you'll see your login record, with your login shell program listed as the last field.
fork, and exec
the command. Your shell should wait for commands to finish,
and should exit when it receives the command
exit.
Using the system function is not allowed,
as it just invokes the system's /bin/sh shell
to do all the work.
You may assume command line arguments are separated by whitespace. Don't do anything special for backslashes, quotes, ampersands or other characters that are ``special'' in other shells. Note that this means 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 your shell should handle input lines of any length.
The executable file for your shell should be named w4118_sh. When testing, make sure you execute your w4118_sh and not /bin/sh.
A few shell commands are not separate programs at all,
but are handled directly by the shell program. You have
already implemented exit, which is an example of
this. Now implement cd, the change directory
command. 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.
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 the entries in the list separated by colons, e.g. "/bin:/usr/bin".
path + /some/dir appends the given pathname to the path list.
path - /some/dir removes the given pathname from the path list.
errno variable (see the function's man page to find out if it does), you should use the result of strerror(errno) as part of your error message.
As far as system calls are concerned, you will want to use one of the
mechanisms described in Reporting Errors or Error Reporting.
"$ ". All error messages must
be of the form "error: %s", strerror(errno). If an error
occurs for which errno is not set, ensure the message begins
with "error:". The remaining text is up to you. To verify the sanity
of your shell's output (and functionality), run this simple version of the grading
script. Once downloaded, you can run this script on the CLIC machines
using the following command python hw1_test.py
"path_to_shell". To run on your own machine you will
need pyexpect, which is
available in most linux distro repositories.