A lightweight, professional, POSIX-compliant UNIX CLI application written in C from scratch. This project demonstrates core operating system concepts such as process creation, inter-process communication (IPC), file descriptor manipulation, and robust signal handling. It closely mirrors the behavior of standard shells like bash or sh while remaining modular, highly documented, and extremely easy to install.
- Execution: Runs standard foreground and background (
&) processes. - Pipelining: Supports unlimited chained pipelines (e.g.,
ls -l | grep src | wc -l). - I/O Redirection: Handles input (
<), output (>), and append (>>) file redirection. - Built-in Commands:
cd,exit, andhistory. - Signal Handling: Gracefully handles
SIGINT(Ctrl+C) without crashing, and automatically reaps background zombie processes viaSIGCHLD. - CLI Options: Supports standard
--helpand--versionflags.
The shell is built with a clean, modular architecture separating concerns across dedicated C modules:
shell.c: The main REPL (Read-Eval-Print Loop).parser.c: Parses raw string input into structuredCommanddata objects.execute.c: Handles single-commandfork()andexecvp()logic.pipe.c: OrchestratesN-1pipes forNcommands, chaining standard I/O streams.redirect.c: Manages file opens anddup2()descriptor mapping.signals.c: Installs isolated signal handlers and manages state restoration for child processes.builtin.c&history.c: Implements internal commands and memory-managed command history.
linux-mini-shell/
├── Makefile
├── README.md
├── CHANGELOG.md
├── CONTRIBUTING.md
├── docs/
├── assets/
├── tests/
├── include/
└── src/
This project extensively utilizes UNIX system calls to interface directly with the kernel:
- Process Management:
fork(),execvp(),waitpid() - IPC & Pipes:
pipe(),dup2() - File I/O:
open(),close(),read(),write() - Signals:
signal(),sigaction(),kill() - Environment:
chdir()
To build and run the project locally, ensure you have gcc and make installed.
# Clone the repository
git clone https://github.com/HarshEvolves/linux-mini-shell.git
cd linux-mini-shell
# Build the project
make
# Run the shell
./minishell# Display help menu
./minishell --help
# Check version
./minishell --versionmyshell$ pwd
/Users/harsh/linux-mini-shell
myshell$ ls
Makefile README.md src include tests assets docs
myshell$ echo Hello
Hello
myshell$ echo Hello > out.txt
myshell$ cat out.txt
Hello
myshell$ ls | grep main
main.c- Logical Operators: Support for
&&and||. - Job Control: Implementation of
fg,bg, andjobscommands usingSIGTSTP. - Quoting & Escaping: Support for parsing strings containing spaces inside double/single quotes.
- Environment Variables: Support for expanding
$VARvariables andexport.
Contributions are always welcome! Please see CONTRIBUTING.md for details on how to get started.
This project is open-source. See the LICENSE file for details.
