A simple command shell

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

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

Goals

Rubric

1 - support "help", printing a short summary of your shell's current features 2 - simplest mode: print prompt; get one-word command from user; execute command (or print an error message); repeat forever 2 - support single commands with command-line arguments (e.g., "wc -l file.txt" or "ls -l -a") 2 - support "command > file" 1 - support "command1 < file" 1 - support "command1 >> file" 2 - support "command1 | command2" 3 - code quality Extra credit 3 - support arbitrary strings of pipes: "command1 | command2 | command3 ..."

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 this project, you will implement the styles of operation listed in the rubric above.

Your shell should be able to handle single-word commands, commands with command-line arguments, redirection of standard output to a file, and redirection of standard output to the standard input of a second command. 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 shell208$ ls -l >> listing.txt shell208$ ./zoo < passcodes.txt shell208$ ls -a | wc -l

NOTE: The above are just example commands. You need to implement these things so they work for (nearly) any command on your system. Mostly, execvp and execlp will take care of this generality for you.

NOTE: Unless you have finished the rest of the assignment, don't try to implement cd. It's a weird case. And if you do want to look into implementing cd, maybe talk to me first.

Submitting your work

Submit your program via Moodle in one of two forms.

Help

I have posted:

Have fun!

This program is pretty cool once you get it working.