A simplified Unix shell written in C, inspired by bash. This project recreates core shell functionality including command execution, piping, redirections, environment variable expansion, heredocs, and built-in commands.
- Interactive prompt with command history (via GNU Readline)
- Command execution with PATH resolution
- Pipes (
|) to chain commands - Redirections
- Input:
< - Output:
> - Append:
>> - Heredoc:
<<
- Input:
- Environment variable expansion (
$VAR,$?) - Quote handling — single (
') and double (") quotes - Signal handling —
Ctrl+C,Ctrl+D,Ctrl+\ - Garbage collector — automatic memory and file descriptor tracking
- Built-in commands:
| Command | Description |
|---|---|
echo |
Print text (supports -n flag) |
cd |
Change directory |
pwd |
Print working directory |
export |
Set/append environment variables |
unset |
Remove environment variables |
env |
Display environment variables |
exit |
Exit the shell |
- OS: Linux
- Compiler:
cc(GCC/Clang) with C99 support - Library:
libreadline-dev
sudo apt-get install libreadline-devmake # Build the project
make clean # Remove object files
make fclean # Remove object files and binary
make re # Full rebuild./minishellThe shell does not accept command-line arguments. Once launched, it presents an interactive prompt:
minishell$ echo hello world
hello world
minishell$ ls -la | grep minishell | wc -l
1
minishell$ cat << EOF
> line 1
> line 2
> EOF
line 1
line 2
minishell$ export FOO=bar
minishell$ echo $FOO
bar
minishell$ exit
.
├── Makefile
├── include/
│ └── minishell.h # Header with all structs, prototypes, and macros
├── main/
│ └── minishell.c # Entry point and main loop
├── parsing/
│ ├── parsing.c # Parsing orchestration
│ ├── tokenize.c # Input tokenization
│ ├── verify_syntax.c # Syntax validation (quotes, pipes, redirections)
│ ├── expand_all.c # Environment variable expansion
│ ├── expand_redir.c # Redirection target expansion
│ ├── handle_redir.c # Redirection extraction from input
│ ├── fill_cmd.c # Build command structs from tokens
│ ├── del_restore_qo.c # Quote removal
│ ├── ft_smart_split.c # Quote-aware string splitting
│ └── ...
├── execution/
│ ├── execution.c # Execution pipeline (fork, pipe, wait)
│ ├── execute_cmd.c # External command execution (execve)
│ ├── signals.c # Signal handlers
│ ├── builtins/ # Built-in command implementations
│ ├── env/ # Environment variable management
│ ├── redirections/ # Redirection and heredoc handling
│ ├── sys_calls/ # Safe wrappers for system calls
│ └── tools/ # PATH resolution, error reporting
├── strings/ # String utility functions
└── garbage_collector/ # Memory and fd tracking