MiniShell is a simple Unix-like command-line shell implemented in C as a learning exercise. This project demonstrates how to:
- Launch external commands using the
execfamily of functions - Implement pipelines (
|) to connect processes - Perform standard input/output redirections (
<,>,>>) - Handle environment variables
- Recognize and execute built-in commands (e.g.,
cd,echo,export,unset,pwd,env,exit) - Manage child processes and handle signals
- Support heredoc (
<<) syntax
Key components include a lexer, parser, executor, signal handler, and integration with GNU Readline for interactive input.
-
Command Parsing
- Tokenization of input, respecting single and double quotes
- Environment variable expansion (e.g.,
$VAR) - Heredoc support (
<<)
-
Command Execution
- Running external programs and scripts
- Handling multiple pipelines
- Redirecting input and output to files
-
Built-in Commands
cd— Change directoryecho— Display a line of textpwd— Print working directoryexport— Set environment variablesunset— Unset environment variablesenv— List environment variablesexit— Exit the shell
-
Signal Handling
- Custom handling for
SIGINT(Ctrl+C) andSIGQUIT(Ctrl+)
- Custom handling for
-
Dependencies
- GNU Readline (v8.2) for command-line editing
- Custom
libftlibrary (constructed as part of the 42 curriculum)
minishell/
├── srcs/
│ ├── lexer/ # Tokenizes input strings
│ ├── parser/ # Builds command trees from tokens
│ ├── exec/ # Executes commands and pipelines
│ ├── builtins/ # Implementation of built-in commands
│ ├── libft/ # Custom C utility library
│ └── redirections.c # Functions for I/O redirection
├── readline/ # Automatically downloaded and built GNU Readline sources
├── Makefile # Build targets and dependency rules
├── leaks.sh # Script to check for memory leaks
└── README.md # Project documentation-
Clone the repository:
git clone https://github.com/faruktinaz/minishell.git cd minishell -
Build the project using the provided Makefile:
make
This command will download and compile the Readline library and build the
minishellexecutable using thelibftutility library.
Start the shell by running:
./minishellWithin the shell, you can:
- Execute standard Unix commands (e.g.,
ls,grep,cat) - Use pipelines and redirections
- Test built-in commands like
cd,export, andexit
To monitor memory leaks while the shell is running, execute in another terminal:
./leaks.sh- The
leaks.shscript periodically checks runningminishellprocesses for memory leaks. - Compiler flags
-Wall -Wextra -Werrorare enabled to catch warnings and treat them as errors.