π ‘ README.md β optimized for your GitHub repo
A simple Unix-like command shell written in C.
This project is an educational shell built from scratch to understand how real shells work at a system level β how commands are parsed, how the OS handles processes, and why some commands must be built-ins.
I built this because I wanted to move beyond syntax and small programs in C, and understand:
- how a shell launches programs,
- how parent and child processes interact,
- how built-in commands like
cddiffer from external commands, - how to handle signals like
Ctrl+C, - how execution and process control work under Linux.
This is a minimal shell focused on clarity and correctness, not on completeness.
β Execute external commands (ls, pwd, date, whoami, etc.)
β Built-in commands:
cd <dir>: change directorypwd: print current directoryhistory: show last typed commandsexit: exit shell
β Basic in-memory command history (last ~20)
β Ctrl+C is handled so the shell doesnβt quit
β Safe input and argument parsing
This shell intentionally does not support:
β Pipes (|)
β Redirection (>, <)
β Background processes (&)
β Quoted arguments (" ")
These features can be added later as extensions.
This shell depends on POSIX system calls, so:
βοΈIt will not work in Windows CMD or PowerShell.
Use a Unix environment such as:
- Linux
- WSL2 on Windows
- Git Bash / MSYS2 (partial)
Tested on: Ubuntu 22.04 (WSL2)
sudo apt update
sudo apt install gcc
2. Clone the repo
git clone https://github.com/CodeAurelius0/Mini-Unix-Shell.git
cd Mini-Unix-Shell
3. Compile
gcc fget.c -o myshell
4. Run
./myshell
You should see:
myshell$
π§ͺ Example Usage
myshell$ pwd
/home/aurelius
myshell$ ls
fget.c
myshell$ history
1 pwd
2 ls
3 history
myshell$ cd ..
myshell$ pwd
/home
myshell$ exit
π‘ How It Works β Quick Overview
Input Handling:
Reads a line with fgets, trims newline.
Tokenization:
Splits input into tokens using strtok.
Built-Ins:
Recognizes cd, pwd, history, exit before creating a process.
Process Creation:
Uses fork() to create a child process.
Command Execution:
Child process runs commands with execvp().
Synchronization:
Parent waits for child with wait().
Signal Handling:
SIGINT is caught so the shell doesnβt quit on Ctrl+C.
π οΈ Code Highlights
Built-In Commands:
cd changes parent directory using chdir()
pwd shows current directory with getcwd()
history prints stored commands
External Commands:
Handled by execvp(), which replaces the child process
Signals:
A handler for SIGINT makes Ctrl+C safe
π§ What I Learned
Differences between a C syntax project and a system-level project
How process creation and replacement actually works
Why some commands must be implemented internally
How to handle OS signals in C
How shells structure command interpretation
π Future Work
Pipe support (|)
I/O redirection (>, <)
Background jobs (&)
Better parsing for quoted strings
These are enhancements β not required for the base shell.
π« Connect
Built by CodeAurelius0 β open to questions, feedback, suggestions.