What is Minishell?
Minishell is a lightweight Unix shell implementation written in C that recreates the core functionality of bash. It provides an interactive command-line interface for executing commands, managing processes, and handling input/output redirection.Minishell is built as a learning project to understand how Unix shells work under the hood, including process management, file descriptors, and command parsing.
Key Features
Built-in Commands
Execute essential shell built-ins like
echo, cd, pwd, export, unset, and env without forking processes.Pipeline Support
Chain multiple commands together using pipes (
|) to redirect output from one command to another.I/O Redirection
Redirect input and output using
<, >, >>, and heredoc (<<) operators for flexible data flow.Environment Variables
Expand environment variables with
$VAR syntax and manage shell environment with export and unset.Signal Handling
Properly handle
Ctrl+C (SIGINT) and Ctrl+\ (SIGQUIT) signals for interactive shell control.Command History
Navigate through previously executed commands using readline’s history feature.
Core Capabilities
Command Execution
Minishell executes both built-in commands and external programs by searching the system’sPATH environment variable:
Built-in Commands
The shell implements seven essential built-in commands:echo- Display text with optional-nflagcd- Change the current working directorypwd- Print the current working directoryexport- Set environment variablesunset- Remove environment variablesenv- Display all environment variablesexit- Exit the shell
Process Management
Minishell handles process execution usingfork() and execve() system calls:
What’s Supported vs. Not Supported
Supported Features
Supported Features
- Single and multiple command execution
- Pipes (
|) for command chaining - Input redirection (
<) - Output redirection (
>and>>) - Heredoc (
<<) - Environment variable expansion (
$VAR,$?) - Single and double quote handling
- Exit status management (
$?) - Signal handling (Ctrl+C, Ctrl+D, Ctrl+)
- Command history (up/down arrows)
Not Supported
Not Supported
- Logical operators (
&&,||) - Wildcards (
*,?,[]) - Background processes (
&) - Subshells (
()) - Command substitution (
`command`or$(command)) - Arithmetic expansion (
$((...))) - Job control (
jobs,fg,bg) - Aliases
- Shell scripting (only interactive mode)
Architecture Overview
Minishell is organized into several key components:- Input Parsing - Reads and tokenizes user input, handling quotes and special characters
- Command Preparation - Creates execution nodes for each command in a pipeline
- Path Resolution - Locates executable files in the system PATH
- Execution Engine - Manages process creation, pipes, and I/O redirection
- Built-in Handler - Executes shell built-in commands directly
Getting Started
Ready to start using Minishell? Follow these guides:Installation
Build Minishell from source and verify your installation
Quick Start
Learn basic commands and try your first pipeline
Exit Status
Minishell maintains an exit status variable (g_status) that stores the return code of the last executed command:
$? in your commands, just like in bash.