Skip to content

CodeAurelius0/Mini-Unix-Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ…‘ 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.

About

A simple Unix-like shell built in C to understand how real shells work internally. This project demonstrates process creation, command execution, built-in commands, history management, and signal handling using POSIX system calls.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors