thumbnail

WSH Shell

CDockerSystems Programming

A Linux Shell made from scratch in C.

For my Operating Systems class, I built a Linux Shell called wsh from scratch in C. The shell supports the following features:

  • built in commands for exit, alias, unalias, history, which, path, and cd
  • batch mode and interactive mode execution
  • piping of commands
  • support for external commands and external processes

The shell is built with several files, a massive main .c file with the main program, and several other files for implementation of necessary data structures needed (dynamic array for history and hash table for aliases). Along with this were subsequent .h files. Testing was done using a combination of valgrind and given test cases to be run in a Docker container.

Some challenges I faced were ensuring that the shell was able to handle all of the edge cases of the commands, properly preventing memory leaks, and all the different error cases that could arise. Piping was a particularly challenging feature to implement due to technical complexity of the system calls needed (dup2, fork, waitpid, etc.), making the code not entirely intuitive to understand.

This certainly has been my favorite project thus far in Operating Systems because it has demystified the internals of shells like bash and zsh that I have used for years.

2025 — Built by Aidan O'Brien