A minimalistic shell inspired by bash, built in C! This project is part of the 42 School curriculum, where we implement our own shell with fundamental UNIX features. π
Minishell is a small-scale Unix shell that mimics the behavior of Bash, implementing key functionalities of a command-line interpreter. It allows users to interact with the system by executing commands, handling input/output redirections, managing environment variables, and supporting pipes for command chaining.
The project focuses on understanding low-level system calls, process control, and memory management. Unlike a full-fledged shell like Bash or Zsh, Minishell is designed to provide a lightweight yet functional experience by implementing core features without unnecessary overhead.
β
Command Execution β Supports running binaries from absolute, relative paths, and using the $PATH environment variable.
β
Built-in Commands β Implements echo, cd, pwd, export, unset, env, and exit without external binaries.
β
Pipelines (|) β Connects multiple commands where the output of one command becomes the input of another.
β
Redirections (<, >, >>, <<) β Handles input and output redirections including here-doc (<<).
β
Environment Variable Expansion ($VAR) β Supports substitution of environment variables like $HOME, $USER, etc.
β
Exit Status ($?) β Stores the exit status of the last executed command.
β
Signal Handling β Reacts to Ctrl+C (displays a new prompt), Ctrl+D (exits), and Ctrl+\ (ignored like in Bash).
β
History Support β Saves and navigates through previously executed commands.
β
Minimal Global Variables β Uses at most one global variable for signal handling, ensuring structured memory management.
β
Error Handling β Properly manages invalid inputs, permission errors, and system call failures.
Make sure you have cc and readline installed on your system.
# Clone the repository
git clone https://github.com/Inzagini/minishell.git
cd minishell
# Compile the shell
make
# Run the shell
./minishellOnce inside minishell, you can run commands just like in a normal shell:
$ ls -l
$ echo "Hello, World!"
$ pwd
$ export MY_VAR=42
$ echo $MY_VAR
$ cat file.txt | grep keyword
$ ls > output.txt| Command | Description |
|---|---|
echo |
Prints text to the terminal (supports -n option) |
cd |
Changes the current directory |
pwd |
Prints the current directory |
export |
Sets environment variables |
unset |
Removes environment variables |
env |
Prints all environment variables |
exit |
Exits the shell |
| Shortcut | Behavior |
|---|---|
Ctrl + C |
Stops the current process and displays a new prompt |
Ctrl + D |
Exits the shell |
Ctrl + \ |
Does nothing (ignored like in Bash) |
minishell/
βββ src/ # Source code files
βββ include/ # Header files
βββ Makefile # Compilation rules
βββ README.md
fork(),execve()β Process executionpipe(),dup2()β Handling pipes and redirectionswaitpid()β Managing child processessignal(),sigaction()β Handling signals
- Izagini GitHub Profile
- paul42b GitHub Profile
Thanks to 42 School for this challenging project! π