A simplified shell implementation written in C, inspired by bash. This project is part of the 42 curriculum and demonstrates core shell functionality including command parsing, execution, piping, redirections, and built-in commands.
- Interactive prompt with command history using GNU readline
- Command parsing with Abstract Syntax Tree (AST) construction
- Command execution with proper process management
- Environment variable management and expansion
- Signal handling for SIGINT (Ctrl+C) and SIGQUIT (Ctrl+)
- Pipes (
|) - Connect multiple commands - Redirections:
- Input redirection (
<) - Output redirection (
>) - Append mode (
>>) - Heredocs (
<<)
- Input redirection (
- Quotes handling:
- Single quotes (
') - literal interpretation - Double quotes (
") - allow variable expansion
- Single quotes (
- Variable expansion (
$VARand$?for exit status)
| Command | Description |
|---|---|
echo |
Display text with -n option support |
cd |
Change current directory |
pwd |
Print working directory |
env |
Display environment variables |
export |
Set/export environment variables |
unset |
Remove environment variables |
exit |
Exit the shell with optional exit code |
.
├── include/ # Header files
├── src/
│ ├── builtins/ # Built-in command implementations
│ ├── core/ # Main shell logic and memory management
│ ├── environment/ # Environment variable handling
│ ├── error/ # Error handling
│ ├── executor/ # Command execution logic
│ ├── expansion/ # Variable expansion and heredoc processing
│ ├── io/ # I/O redirection and heredoc handling
│ ├── parser/ # Command parser and AST builder
│ ├── signals/ # Signal handling
│ ├── tokenizer/ # Lexical analysis
│ └── utils/ # Utility functions
├── lib/ # External libraries (libft)
└── Makefile
- GCC or Clang compiler
- GNU Readline library
- Make
make
make clean
make fclean
make re# Run the shell
./minishell
# Interactive mode
minishell$ ls -la | grep minishell
minishell$ echo "Hello, World!"
minishell$ export MY_VAR=value
minishell$ echo $MY_VAR
minishell$ exit# Simple commands
minishell$ ls
minishell$ pwd
# Pipes
minishell$ ls -la | grep txt | wc -l
# Redirections
minishell$ echo "hello" > file.txt
minishell$ cat < file.txt
minishell$ echo "world" >> file.txt
# Heredocs
minishell$ cat << EOF
> This is a heredoc
> Multiple lines supported
> EOF
# Environment variables
minishell$ echo $HOME
minishell$ echo $?
minishell$ export PATH=$PATH:/new/path- Readline - Read user input with history support
- Tokenizer - Break input into tokens (words, operators)
- Parser - Build Abstract Syntax Tree (AST) from tokens
- Expansion - Expand variables and process heredocs
- Executor - Execute commands, handle pipes and redirections
The shell uses a garbage collector (t_gc) to manage memory during command execution, ensuring proper cleanup after each command.
Ctrl+C(SIGINT): Interrupt current command, display new promptCtrl+\(SIGQUIT): Ignored in interactive modeCtrl+D(EOF): Exit the shell
This is an educational implementation with some limitations compared to full bash:
- No support for
&&,||, or;operators - No wildcards/globbing (
*,?) - No command substitution (
$(command)or`command`) - Limited history expansion features
This project is part of the 42 School curriculum. See the 42 School guidelines for usage terms.