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
- Practice manipulating Linux processes in C
- Demystify command shells like bash, zsh, etc.
- Understand how command-line arguments are arranged in memory
Rubric
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:
- print a prompt for the user
- read the user's command
- execute the command
- wait for the command to finish
- 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:
Submitting your work
Submit your program via Moodle in one of two forms.
Option 1: a single C source file named shell208.c. This program should compile without warnings on mantis using:
gcc -Wall -Werror -g -Og -o shell208 shell208.cOption 2: a shell208.tar file containing a folder named shell208, which in turn contains any files your shell needs. This tar file must include a Makefile that enables us to compile and run your shell on mantis like so:
tar xvf shell208.tar cd shell208 make shell208 ./shell208
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):
- Process-related samples on the samples page. These demonstrate all of the essential techniques you will need to complete this assignment, and more. You'll mostly be repurposing the sample programs and making sure your resulting logic fits together.
- Two videos to help you with this assignment. They are linked on the main course page. These videos repeat some of the stuff I've done in class, but videos are considerably easier to replay and pause than class is.
Have fun!
This program is pretty cool once you get it working.