C++ Shell
Building a Unix-like command-line shell in modern C++, exploring command parsing, executable discovery, and operating system interfaces.
Overview
An ongoing project to build a Unix-like command-line shell from scratch in modern C++, following the CodeCrafters Build Your Own Shell challenge.
The goal is to better understand how shells interpret commands, interact with the operating system, and launch programs.
Current Features
Read-Eval-Print Loop
Implemented an interactive command loop that reads user input, processes commands, and displays a prompt.
The shell handles end-of-file input gracefully and continues accepting commands until explicitly exited.
Built-in Commands
Currently supports:
echo— Prints text to standard output.exit— Exits the shell.type— Identifies built-in commands and locates executable programs.
Executable Discovery
Implemented command lookup using the PATH environment variable.
The shell:
- Reads the system’s
PATH. - Searches directories in order.
- Checks whether a matching file exists.
- Verifies that the file is executable.
- Reports its location or indicates that the command was not found.
This functionality uses POSIX interfaces including stat() and access().
Planned Features
As development progresses, I intend to explore:
- Executing external programs.
- Parsing quoted strings and escape sequences.
- Input and output redirection.
- Command pipelines.
- Additional built-in commands.
Technologies
- C++20 — Core implementation using modern standard library features.
- POSIX APIs — Filesystem inspection and executable permission checks.
- CMake — Build configuration.
- CodeCrafters — Incremental implementation and automated testing.