Minishell is a minimalistic Unix shell implemented in C, replicating core behaviors of Bash with a focus on learning system calls, process handling, and parsing logic. Built as part of the 42 curriculum, this project introduces you to building your own command-line shell with custom parsing, environment management, and execution logic.
-
Execution of binaries from PATH and with absolute/relative paths
-
Built-in commands:
echo,cd,pwd,export,unset,env,exit
-
Redirections:
>,>>,<,<<(heredoc with correct handling of quotes and signals)
-
Pipes:
cmd1 | cmd2 | cmd3 -
Environment variables:
$VAR, including proper expansion -
Quote handling:
- Single quotes
'prevent expansion - Double quotes
"allow expansion
- Single quotes
-
Signal handling (
Ctrl+C,Ctrl+D) with prompt restoration -
Exit status propagation
-
Wildcard (
*) expansion for current directory -
Logical operators (Bonus):
&&,||for conditional execution
-
Parentheses
( )(Bonus) for grouped commands and prioritization
The first step splits the user input into tokens while respecting shell grammar (quotes, operators, etc.).
The lexer output is parsed into an Abstract Syntax Tree (AST) representing command execution flow.
The AST is traversed to execute commands:
- Pipes are forked and connected via
dup2 - Redirections are opened and applied before command execution
- Built-ins are executed in the parent or child depending on context
- Logical operators (
&&,||) are handled via AST nodes
Heredocs are processed in a forked child and stored in temporary files. They respect quotes and stop on correct delimiters or on signal SIGINT.
When encountering *, minishell expands it to match filenames in the current directory using opendir() and readdir().
- β
Logical operators:
&&,|| - β
Parenthesis grouping:
(...) - β
Wildcard expansion:
*
make
./minishellType commands just like in bash:
π€ minishell echo Hello $USER
Hello othmane
π€ minishell ls -l | grep minishell
-rwxr-xr-x 1 othmane staff 134528 May 6 15:42 minishell
π€ minishell cat << EOF
Hello minishell
EOF
Hello minishell
π€ minishell mkdir test && cd test || echo fail
π€ minishell (echo one && echo two) || echo three
one
two
π€ minishell echo *
file1.txt file2.c minishell README.md
π minishell ls no_such_file
ls: cannot access 'no_such_file': No such file or directoryCtrl+Cinterrupts the current input or heredoc and restores the promptCtrl+Dexits the shell or ends input when appropriate
This project was developed collaboratively by a team of students at [1337 School / 42 Network].
@bg-otman
@Aymanesaj