Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

72 Commits

Folders and files

Repository files navigation

Mini Shell

A simple Unix-like shell written in C for learning and experimentation.

Mini-Shell Demo

Prerequisites

  • Linux or macOS with a POSIX userland
  • gcc or clang
  • make
  • C standard: C17; uses POSIX.1-2008 APIs

Quickstart

git clone https://github.com/blazejOz/mini_shell mini_shell
cd mini_shell
cmake -B build
./build/mini_shell

Try it with Docker

You don't need to compile anything to try out mini_shell. You can run the latest version directly from GitHub Packages:

docker run -it --rm ghcr.io/blazejoz/mini_shell:latest

The -it flags are required to interact with the shell's prompt. The --rm flag ensures the container is cleaned up after you exit.

Project Structure

mini_shell/
├── src/                # Source code files
│   ├── main.c          # Entry point of the shell
│   ├── shell.c         # Shell loop and command execution
│   ├── builtins.c      # Implementation of built-in commands
│   ├── parser.c        # Command parsing and tokenization
│   └── utils.c         # Utility functions
├── include/            # Header files
│   ├── shell.h
│   ├── builtins.h
│   ├── parser.h
│   └── utils.h
├── tests/              # Test files
│   ├── test_builtins.c
│   ├── test_parser.c
├── Makefile            # Build instructions
└── README.md           # Project documentation

Features

  • Interactive Shell Loop: Robust REPL (Read-Eval-Print Loop) with a clean prompt.
  • Advanced Command Pipeline: Supports chaining multiple commands using the | operator.
    • Efficiently handles $N$ processes with $N-1$ concurrent pipes.
    • Proper file descriptor management (uses dup2 for I/O redirection between stages).
    • Synchronous execution: The shell waits for the entire pipeline to complete before returning to the prompt.
  • Intelligent Command Dispatcher:
    • Built-in Commands: Executed directly in the parent process (cd, exit, pwd, echo).
    • External Binaries: Discovered via $PATH and executed in forked subshells using execvp.
  • Memory Safety: Implements a multi-level cleanup strategy to ensure no memory leaks during parsing or execution.

Roadmap & Planned Features

  • Process Pipelines: Concurrent execution of piped commands.
  • External Execution: Full integration with system binaries via exec.
  • I/O Redirection: Implementing file descriptor hijacking for >, >>, and <.
  • Signal Handling: Graceful management of Ctrl+C (SIGINT) and Ctrl+Z (SIGTSTP).
  • Variable Expansion: Support for $HOME, $USER, and local shell variables.
  • Persistence: Command history saved to ~/.mini_shell_history.

Building

cmake -B build
cmake --build build

Running

./build/mini_shell

Testing

./build/unit_tests

License

MIT License


This project is for educational purposes and demonstrates basic shell concepts and system programming in C.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages