Skip to content

siddharthsiva/mini-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mini Shell – Custom C/Linux Command Line Shell

A powerful and extensible shell written in C for Linux/macOS. Supports advanced shell features such as piping, redirection, alias persistence, job control, environment variable expansion, command substitution, scripting, colored output, and more.

Features

  • Command Execution: Run any Linux command like ls, echo, cat, etc.
  • Built-in Commands: Includes cd, exit, alias
  • Piping (|): Connect commands like ls | grep txt
  • I/O Redirection (>, <): Output to or input from files
  • Background Jobs (&): Run commands without blocking the shell
  • Command Chaining: Logical operators: &&, ||, and ;
  • History Support: GNU readline based up/down navigation
  • Tab Completion: Autocomplete for files and commands
  • Alias Support + Persistence: Define aliases, saved to ~/.mini-shellrc
  • Colored ls Output: Automatically adds --color=auto for clarity
  • Environment Variable Expansion: Supports $HOME, $USER, etc.
  • Command Substitution ($(...)): Replace with output of another command
  • Job Control: jobs, fg, bg, kill
  • Script Execution: Run a .txt file with multiple shell commands
  • Colored Prompt: Green mini-shell$ prompt with ANSI codes
  • Runtime Timer: Show execution time for each command

Build Instructions

Requirements

  • GCC or Clang
  • GNU readline library
  • Linux/macOS terminal

Compile

make

Clean

make clean

Usage

./mini-shell                # Start interactive shell
./mini-shell script.txt     # Run commands from a file

Example Commands

Basic Usage

echo Hello
cd /
pwd

Aliases

alias ll='ls -l'
ll

Variable and Substitution

echo $USER
echo Home: $HOME
echo Today is: $(date)

Pipes, Redirection, Background

ls | grep .c
echo Hello > file.txt
cat < file.txt
sleep 5 &

Command Chaining

true && echo success
false || echo fallback
echo First ; echo Second

Job Control

sleep 10 &
jobs
fg %1
bg %1
kill %1

Script Execution

Create script.txt:

echo Starting script...
ls
echo Done!

Then run:

./mini-shell script.txt

Alias Persistence

  • Aliases are saved to ~/.mini-shellrc
  • Loaded automatically each time the shell starts

Example .mini-shellrc:

alias ll=ls -l
alias gs=git status

Project Structure

mini-shell/
├── src/
│   ├── main.c
│   ├── parser.c
│   ├── executor.c
│   ├── builtins.c
│   ├── piping.c
│   ├── redirection.c
│   ├── history.c
│   ├── aliases.c
│   ├── chaining.c
│   ├── timer.c
│   ├── script.c
│   ├── jobs.c
├── include/
│   └── shell.h
├── Makefile
├── .gitignore
└── README.md

.gitignore

mini-shell
*.o
*.out
.DS_Store
.history
.mini-shellrc

Author

Siddharth Sivalanka
Built as a full-featured first-year systems project to explore C, POSIX, Linux internals, and interactive shell design.

About

Shell commands with more additional functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors