A simple command shell: part 1

Upload via Moodle as: shell.tar or shell208.c

As usual, you are welcome to work with a partner if you wish.

Goals

Rubric

Maximum score: 12 points 1 - support "help", printing a short summary of your shell's current features 3 - simplest mode: print prompt; get one-word command from user; execute command (or print an error message); repeat forever 3 - support single commands with command-line arguments (e.g., "wc -l file.txt" or "ls -l -a") 3 - support "command > file" (redirecting command's stdout to a file) 2 - code quality

Background

When you interact with a Unix (or other similar) command prompt, you are interacting with a program known as a command shell. This might be bash in a WSL or Linux terminal, bash in the terminal in VS Code, zsh in a macOS Terminal, PowerShell in Windows, cmd in a Windows "command prompt" window, etc.

Though command shells are typically sophisticated programs with many features and they often implement their own full-fledged programming languages (e.g., "bash scripting"), their flow of control is, at heart, conceptually very simple:

  1. print a prompt for the user
  2. read the user's command
  3. execute the command
  4. wait for the command to finish
  5. go to step 1

Your assignment

You will write a simple command shell, named shell208, that performs the most common operations that shells perform. For Part 1 of this project, you will implement the styles of operation listed in the rubric above.

For Part 1, your shell should be able to handle single-word commands, commands with command-line arguments, and redirection of standard output to a file. For example, each of the following should work as they do in bash on mantis:

shell208$ help shell208$ ls shell208$ ls -l mysubdirectory shell208$ ls -l > listing.txt

Submitting your work

Submit your program via Moodle in one of two forms.

Help

I have posted a collection of sample programs that demonstrate all of the essential techniques you will need to complete this assignment. You'll mostly be repurposing the sample programs and making sure the logic fits together.

I have posted (or will post):

Have fun!

This program is pretty cool once you get it working.