A modular, POSIX-compliant shell implemented in C, following the RPEL (Read-Parse-Execute-Loop) architecture. This project serves as a foundation for understanding OS-level process management, memory handling, and terminal interaction.
The shell is designed with modularity in mind, separating concerns into individual components:
- Read:
read_line.c: Handles interactive input usinggetline.read_stream.c: Handles piped/scripted input using a character-by-character buffer.
- Parse:
split_line.c: Tokenizes input into commands and arguments usingstrtok. Supports comments (#).
- Execute:
execute_args.c: A dispatcher that checks for built-in commands before attempting to launch external programs.builtins.c: Internal implementations forcd,env,help, andexit.new_process.c: Creates child processes usingfork(), replaces them withexecvp(), and monitors status withwaitpid().
- Loop:
shell_interactive.c: Manages the prompt and life cycle for terminal usage.shell_no_interactive.c: Manages execution flow for non-terminal input.
This shell relies on POSIX system calls (fork, exec, wait). Follow the instructions below based on your Operating System.
- Install Build Tools:
sudo apt update sudo apt install build-essential
- Compile and Run:
make hsh ./hsh
- Install Command Line Tools:
xcode-select --install
- Compile and Run:
make hsh ./hsh
Native Windows (Command Prompt/PowerShell) does not support the fork() system call. To run this shell, you MUST use a POSIX-compatible layer.
- Open PowerShell as Administrator and run:
wsl --install. - Restart your PC and open the Ubuntu terminal.
- Follow the Linux instructions above.
- Install MSYS2.
- Open the MSYS2 MINGW64 terminal.
- Install the toolchain:
pacman -S mingw-w64-x86_64-toolchain make. - Compile using
make hsh.
Run the shell directly to see the prompt:
./hsh
simple_prompt$ ls -l
simple_prompt$ cd ..
simple_prompt$ helpPipe commands into the executable:
echo "ls -l" | ./hshTo remove compiled object files and the executable:
make clean- Environment: Does not run natively on Windows
cmd.exe. - Features: Does not currently support piping (
|), redirection (>,<), or globbing (*). - Expansion: Environment variable expansion (e.g.,
$HOME) is handled by the system'sexecvpbut not by the parser itself for argument building.