Skip to content

lauracibei/microbash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐚 microbash: A Custom Unix Shell

A lightweight, custom Unix shell implemented entirely in C. This project is a hands-on exploration of Operating System principles, designed to parse and execute commands just like standard shells (e.g., bash, zsh), while managing processes, file descriptors, and inter-process communication under the hood.

✨ Key Features

  • Command Execution: Runs standard Unix system commands using the exec family of system calls.
  • Built-in Commands: Native support for essential shell commands like cd (change directory) and exit.
  • I/O Redirection: Supports redirecting standard input (<) and standard output (>) to files.
  • Piping (|): Connects the standard output of one command to the standard input of another, allowing command chaining.
  • Background Processes (&): Executes commands in the background without blocking the shell prompt.

📂 Project Structure

  • microbash.c: The core source code containing the shell loop, string parsing logic, and system call invocations.
  • Makefile: The build configuration file for easy compilation.
  • microbash.pdf: Detailed project specification and architectural documentation.
  • test.txt: A sample text file used to verify I/O redirection and piping functionalities.

🛠️ Technologies & Concepts

  • Language: C
  • API: POSIX (Portable Operating System Interface)
  • Process Management: fork(), execvp(), waitpid()
  • Inter-Process Communication (IPC): pipe()
  • File Operations: open(), close(), dup2()

🚀 How to Build and Run

  1. Open your terminal in the project directory.
  2. Compile the shell using the provided Makefile:
    make
  3. Run the compiled executable to start the shell interface:
    ./microbash

(To exit the shell, simply type exit or press Ctrl+D)

🧠 What I Learned

Building a shell from the ground up is a classic and rigorous exercise in Systems Programming. Through microbash, I developed a deep understanding of:

  • Process Lifecycle: How the OS creates child processes (fork), replaces their memory images (exec), and synchronizes with the parent (wait).
  • File Descriptors: How Unix treats files and I/O streams, and how to safely manipulate them using dup2 to achieve redirection.
  • Inter-Process Communication: Creating anonymous pipes to establish one-way data channels between concurrent processes.
  • C String Manipulation: Safely tokenizing user input, handling dynamic memory, and dealing with pointers in a low-level environment.

About

A lightweight, custom Unix shell built in C. Features command execution, I/O redirection, piping, and background processes using POSIX APIs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors