3013 Project 1

JSH- The Java Shell

Due date: Tuesday, September 7th, at Midnight



This assignment is intended to introduce you to the process manipulation facilities in the Unix Operating System. You are to implement the program described below on any CCC Unix machines in Java.

You are to write a program that simulates a simple Unix command line shell. Your program will allow a user to enter commands one at a time until s/he types "exit".

Not all commands will be executed externally. Your shell will also have several "built-in" commands. These commands will be handled internally by your java-shell and will not be executed. The built-in commands are:

Note, however, that your program should have error checking. You must check the return values from system calls and print appropriate error messages to the user, when required.

Java Resources

I've put up some Java code samples on the course web page.

Here are only some of the many online sites at Sun you may find useful for programming in Java:

There are lots of other places to go for Java information. Here are a few:


Java Tools




The following Java methods and classes might be useful:

A few recommendations if you find yourself struggling (in order):

  1. Download the java programs from the samples section of the web page. Get them to compile and run. Familiarize yourself with them.
  2. Build a simple program that does nothing but an exec() with a hard-coded command (ie - ls -l).
  3. Add the built-in exit command.
  4. Add a loop for the parent and the waitFor() call.
  5. Add the built-in cd command.
  6. Polish, clean-up, debug thoroughly, error checking ...
  7. Turn it in.
  8. Relax! (Until project 2, that is).

Remember, do each step thoroughly. Make sure the step you are on works well and you understand it before going to the next step.


  1. You should observe how your tiny shell works compared to a full-fledged Unix shell, such as tcsh or bash. What are some of the process features the Unix shell has that your tiny shell does not?

  2. Shells typically allow processes to be run in "background" mode using the '&' character. In background mode, the shell does not wait for the current process to complete but instead prompts the user for the next command. Briefly describe changes you would make to your code to support the '&' character.

  3. Will your jsh be portable to every program that has a java virtual machine? Why or why not?

Hand In

A completely working program will function as described above. There are several levels of less sophisticated programs that can be achieve to receive lesser grades. Here is a rough summary of the grades that will be assigned:

Note, one letter grade is worth approximately 10% of the Project points.

You should roughly follow the CS department's documentation standard. The main information I'd like you to have from the documentation standard is; author, date, project id, language, OS dependencies, description and building information. In addition, there are a couple of short-answer questions for the lab that you should include (see above). Do note, however, that this information does not take the place of normal comments in your code!

All this information can appear as code comments in the header of your program or in a separate file. If you choose to put the information in a separate file, please name the file something like README. Also, be sure to turn-in you file when you turn-in your source code!

Here is a sample of the information you should have:

Author:                         Mark Claypool
Date:                           9/9/99
Project ID:                     Project 1
CS Class:                       CS3013
Programming Language:           Java
OS/Hardware dependencies:       Digital Unix

Problem Description:            This program implements a small shell
                                that does blah, blah, blah

How to build the program:       java jsh.java

You will turn in your assignment using the "turn-in" program. Check here for information on how to turn in your assignments.

Return to 3013 Home Page

Send all questions to the TA mailing list.