A minimal interactive Unix-like shell written in C++23.
It supports:
- interactive prompt (GNU readline)
- command history (saved to a file)
- basic builtins
- running external commands via
execvp - pipelines (
cmd1 | cmd2 | ...) - stdout/stderr redirection (
>,>>,2>,2>>,1>,1>>) - tab completion for builtins and executables found in
$PATH
- Linux / macOS (POSIX:
fork,execvp,waitpid,pipe) - CMake >= 3.13
- A C++ compiler with C++23 support
readlinedevelopment package
On Debian/Ubuntu:
sudo apt-get update
sudo apt-get install -y build-essential cmake libreadline-devOn Fedora:
sudo dnf install -y gcc-c++ cmake readline-develcmake -S . -B build
cmake --build build -jThe binary will be:
build/shell
./build/shellYou should see a banner and a prompt:
patryk-shell v0.1 $
Implemented builtins (see src/builtins.cpp):
echo ...– prints argumentspwd– prints current directorycd <dir>– changes directory (supports~expansion)type <cmd>– prints whether command is a builtin or a path-resolved executablehistory– prints historyhistory -r <file>– read history from filehistory -w <file>– write history to filehistory -c– clear in-memory historyhistory -a <file>– append new entries since last save
exit– exits the shell (and saves history)
Pipelines are supported using |:
ls -la | grep cpp | wc -lSupported operators:
>/1>– redirect stdout (truncate)>>/1>>– redirect stdout (append)2>– redirect stderr (truncate)2>>– redirect stderr (append)
Examples:
echo hello > out.txt
ls does-not-exist 2> err.txt
ls -la >> out.txtHistory is stored in:
$HISTFILEif set- otherwise
.my_shell_historyin the current working directory
Key files:
src/main.cpp– REPL loop + dispatch (builtins / external / pipelines)src/parser.cpp– parsing input / redirections / pipelinessrc/executor.cpp– running external commands and pipelinessrc/builtins.cpp– builtin implementationssrc/completions.cpp– readline completionsrc/utils.cpp– helper functions + banner + history helpers
This is a learning project and intentionally minimal.
Not implemented (yet):
- job control (
fg,bg, signals) - environment variable expansion (
$VAR) - globbing (
*.cpp) - advanced quoting/escaping edge cases
- background execution (
&)
MIT (or specify your preferred license). If you want, add a LICENSE file.