A minimal POSIX-compliant shell written in C that interprets commands, executes external programs, and supports built-in commands.
- Prompt display: Shows a prompt and waits for user input
- Error handling: Gracefully handles invalid commands
- REPL loop: Continuously reads, evaluates, and executes commands.
- Built-in commands:
- exit: Exit the shell
- echo: Print text to stdout
- type: Identify whether a command is a built-in or an executable
- pwd: Print the current working directory
- cd: Change directories: Absolute paths, Relative paths, Home directory (cd ~)
- Quoting support:
- Single quotes
- Double quotes
- Backslash escaping (inside and outside quotes)
- Executing quoted executables
- I/O Redirection:
- Redirect stdout (>)
- Redirect stderr (2>)
- Append stdout (>>)
- Append stderr (2>>)
-
Tab completion:
- Built-in completion
- Executable completion
- Multiple and partial completions
-
Pipelines:
- Dual-command pipelines
- Built-in commands in pipelines
- Multi-command pipelines
-
Command history:
- View history
- Up/down arrow navigation
- Execute commands from history
- Persistent history (save/load from file)
- Language: C (C99 standard)
- Standards Compliance: POSIX
- Platform: Developed and tested on Linux. Compatible with macOS (POSIX-compliant). Windows support would require adapting process and file descriptor APIs to WinAPI.
- Build System: CMake (project configuration) with Ninja (fast incremental builds)
- Compiler: Clang (tested; GCC compatible)
- Package Manager: vcpkg for dependency management
- clone the repository
git clone git@github.com:raphico/shell-c.git
cd shell-c
- run the program
./your_program.sh
├── include/ # Header files
├── src
│ ├── builtins/ # Built-in command implementations
│ ├── main.c # Entry point: initializes and runs the shell REPL loop
│ ├── parser.c # Tokenizes user input and parses redirection operators
│ ├── redirects.c # Handles applying/restoring I/O redirections before/after command execution
│ └── shell.c # Dispatches built-in commands or executes external programs
└── your_program.sh # Shell script to run or test the program
This project was built as part of the Codecrafters "Build Your Own Shell" Challenge