A small Unix-like shell written in C++23 for the CodeCrafters "Build Your Own Shell" challenge.
This is a learning project focused on command parsing, builtin commands, executable lookup, and process creation. The implementation grows as I work through the challenge and refactor what I learn along the way.
- Interactive read-eval-print loop with a
$prompt. - Builtin commands:
exit,echo,type,pwd, andcd. - Executable lookup through
PATH, including checks for executable permissions. - External program execution using
fork,execv, andwaitpid. - Argument parsing for single and double quotes, adjacent quoted fragments, and backslash escapes. Context-specific escape rules are still being refined.
| Builtin | Behavior |
|---|---|
exit |
Exit the shell. |
echo |
Print the parsed arguments. |
type |
Identify a builtin or locate an executable in PATH. |
pwd |
Print the current working directory. |
cd |
Change the current directory, including cd ~ for the home directory. |
Requirements:
- A POSIX environment, such as Linux or macOS.
- A compiler and standard library supporting C++23.
- CMake 3.13 or later.
- The Readline library available to the linker; the CMake target links against
readline.
From the repository root:
./your_program.shThe script configures CMake, builds the executable in build/, and starts the
shell. If VCPKG_ROOT is set, it uses the vcpkg toolchain from that directory;
otherwise, it uses the default toolchain.
To build and run manually with the default toolchain:
cmake -B build -S .
cmake --build build
./build/shellOnce the shell is running, enter these commands at its $ prompt:
echo hello shell
echo 'hello shell'
echo 'hello''world'
echo "shell's" test
echo hello\ world
type pwd
pwd
ls
cd ..
exitExternal programs such as ls and cat must be available in PATH. To read an
existing file whose name contains spaces, use cat 'file with spaces.txt'.
With the CodeCrafters CLI configured for this repository, run the current stage:
codecrafters testTo include all previous stages as well:
codecrafters test --previousTo submit the solution:
codecrafters submitThis is an implementation in progress, with partial shell syntax support.