Skip to content

🐚 Minishell is a simple UNIX shell written in C as part of the 42 School curriculum. It supports command execution, pipes, redirections, environment variables, and built-in commands like cd, echo, and export. Inspired by Bash, Minishell handles signals and ensures efficient memory management. πŸš€

Notifications You must be signed in to change notification settings

Inzagini/minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐚 Minishell

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. πŸš€

πŸ“ What is Minishell?

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.

πŸ” Key Features & Objectives

βœ… 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.

⚑ Installation

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
./minishell

πŸš€ Usage

Once 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

πŸ”§ Built-in Commands

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

πŸ“Ά Signal Handling

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)

πŸ“‚ Project Structure

minishell/
│── src/          # Source code files
│── include/      # Header files
│── Makefile      # Compilation rules
│── README.md

πŸ›  System Calls Used

  • fork(), execve() β†’ Process execution
  • pipe(), dup2() β†’ Handling pipes and redirections
  • waitpid() β†’ Managing child processes
  • signal(), sigaction() β†’ Handling signals

πŸ‘¨β€πŸ’» Authors

🌟 Acknowledgments

Thanks to 42 School for this challenging project! πŸŽ“

About

🐚 Minishell is a simple UNIX shell written in C as part of the 42 School curriculum. It supports command execution, pipes, redirections, environment variables, and built-in commands like cd, echo, and export. Inspired by Bash, Minishell handles signals and ensures efficient memory management. πŸš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •