Skip to content

Latest commit

 

History

History
176 lines (108 loc) · 3.42 KB

File metadata and controls

176 lines (108 loc) · 3.42 KB

🅡 README.md — optimized for your GitHub repo

Mini Unix Shell

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.

⚠️ It is not a full shell like Bash/Zsh — it's a learning implementation.


🔍 Purpose

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 cd differ 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.


🧪 Features

✔ Execute external commands (ls, pwd, date, whoami, etc.)
✔ Built-in commands:

  • cd <dir> : change directory
  • pwd : print current directory
  • history : show last typed commands
  • exit : exit shell
    ✔ Basic in-memory command history (last ~20)
    ✔ Ctrl+C is handled so the shell doesn’t quit
    ✔ Safe input and argument parsing

🧱 Limitations

This shell intentionally does not support:

❌ Pipes (|)
❌ Redirection (>, <)
❌ Background processes (&)
❌ Quoted arguments (" ")

These features can be added later as extensions.


⚙️ Requirements

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)


🚀 Build & Run (Beginner Friendly)

1. Install prerequisites (Linux/WSL)

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.