A Unix shell implementation in C, built as part of the 42 school curriculum. Minishell replicates core Bash behavior including command execution, pipelines, redirections, environment variable expansion, and built-in commands.
- kchaouki
- rrhnizar
- Interactive prompt with command history (via GNU Readline)
- Command execution with
PATHresolution - Single and double quote handling
- Environment variable expansion (
$VAR,$?) - Input/output redirections:
<,>,>> - Here-doc (
<<) - Pipes (
|) - Signal handling:
Ctrl+C,Ctrl+D,Ctrl+\
- Logical operators:
&&and||with parentheses for grouping - Wildcard expansion (
*) in the current directory - Subshell execution
| Command | Description |
|---|---|
echo |
Print text (-n flag supported) |
cd |
Change directory (absolute/relative paths) |
pwd |
Print working directory |
export |
Set or display environment variables |
unset |
Remove environment variables |
env |
Print environment |
exit |
Exit the shell with a status code |
minishell/
├── minishell.c # Entry point, main loop, signal handling
├── minishell.h # Global header and struct definitions
├── minishell_utils.c # Utility functions
├── all_free.c / all_free2.c # Memory cleanup
├── parsing/
│ ├── parser.c # Main parser
│ ├── create_tokens.c # Tokenizer
│ ├── global_split.c # Input splitting
│ ├── here_doc.c # Here-doc handling
│ ├── define_mandatory.c / define_bonus.c
│ ├── synt_error_mandatory.c / synt_error_bonus.c
│ └── analyzer/ # Syntax analysis and error detection
├── execution/
│ ├── exec_commands.c # Command dispatching
│ ├── exec_cmd.c # Command execution
│ ├── pipe.c # Pipe creation and management
│ ├── redirections.c # Redirection setup
│ ├── and_or.c # `&&` / `||` logic
│ ├── subshell.c # Subshell execution
│ ├── wildcard.c # Wildcard expansion
│ ├── builtins/ # Built-in command implementations
│ └── expention/ # Variable and redirection expansion
└── libft/ # Custom C standard library
- GCC with
-Wall -Wextra -Werror - GNU Readline library
On macOS (using Homebrew):
brew install readline# Mandatory version
make
# Bonus version (&&, ||, subshells, wildcards)
make bonus
# Clean object files
make clean
# Full clean (removes binaries)
make fclean
# Rebuild
make reNote: The Makefile is configured with a specific Readline path (
/goinfre/kchaouki/brew/opt/readline). You may need to update theRDLand include path in the Makefile to match your local Readline installation.
./minishell./minishell_bonus # bonus versionOnce running, the shell presents a minishell ~ prompt and accepts commands just like Bash.
minishell ~ echo "Hello, World!"
minishell ~ ls -la | grep .c
minishell ~ export MY_VAR=42 && echo $MY_VAR
minishell ~ cat << EOF
minishell ~ pwd > output.txt
minishell ~ exit 0- Only one global variable is used (
g_r) to store the signal state, in compliance with 42 school norms. - All allocated memory is freed before exit.
- The shell handles
Ctrl+Cby displaying a new prompt,Ctrl+Dby exiting cleanly, andCtrl+\is ignored (matching Bash behavior).