Minishell is a core project from the 42 curriculum that replicates the behavior of a simplified Unix shell. It aims to deepen your understanding of process management, file descriptors, signals, parsing, and job control by building your own command-line interpreter from scratch in C.
- π§ Custom shell parsing and syntax handling
- π Support for sequential and piped command execution
- πͺ Built-in commands:
cd,echo,env,exit,export,pwd,unset,history - π Environment variable management and expansion (
$VARsupport) - π§± Redirections: input
<, output>, append>>, and heredocs<< - π Full support for pipelines using
| - π§Ό Proper memory and file descriptor management
- πΆ Signal handling: handles
EOF(ctl+D),SIGINT(Ctrl+C) andSIGQUIT(Ctrl+\) gracefully - π§΅ Forking and process execution with correct exit codes
- π§ͺ Error handling for syntax errors and "command not found"
- π Command history persistence across sessions
- π§ Advanced quoting, escaping, and syntax error detection
- πͺ Auto-completion support (via readline hooks)
- π Custom shell prompt
- Parse and execute commands using
fork()andexecve() - Wait for child processes using
wait()/waitpid()and return correct exit statuses - Execute piped commands by managing file descriptors correctly
- Split and analyze user input: detect pipes, redirections, quotes, and variable expansions
- Respect shell grammar: handle nested quotes (
',") and escape characters - Handle empty inputs and multiple spaces or tabs gracefully
echo [-n]β Print argumentscd [dir]β Change current directorypwdβ Print working directoryexport VAR=valβ Set environment variableunset VARβ Remove variableenvβ List environment variableshistoryβ Show command history for the current sessionexit [code]β Exit the shell with an optional status code
>β Redirect output (overwrite)>>β Redirect output (append)<β Redirect input<<β Heredoc input until limiter is found
- Handle
$VARexpansion from the current environment and local variables - Expand variables inside double quotes
", but not inside single quotes'
Ctrl+C(SIGINT) β Interrupts current input line without exitingCtrl+\(SIGQUIT) β Ignored in the main shell, passed to child processes like in BashCtrl+D(EOF) β Exits the shell if the input line is empty (end-of-file condition)
-
β No use of
system(),printf(), or external parsing libraries -
β Must use
readlinefor line input and command history -
π No memory or file descriptor leaks (must pass
valgrindorleaks) -
π Code must comply with 42 Norminette:
- Maximum 25 lines per function
- Maximum 4 variables per function
- Maximum 4 arguments per function
To compile the project, simply run:
makeThis will generate the minishell executable.
Start your shell with:
./minishellYou'll be greeted with a custom prompt where you can type commands just like in Bash.
- Use up/down arrows to navigate command history
- Chain commands using pipes (
|) - Redirect output and input using
>,>>,<, and<< - Use
Ctrl+Cto cancel a running foreground command - Type
exitto quit the shell
zmbash-2.5$ echo hello | cat -e
hellozmbash-2.5$
zmbash-2.5$ export NAME=world
zmbash-2.5$ echo $NAME
world
zmbash-2.5$
zmbash-2.5$ ls > out.txt
zmbash-2.5$ cat < out.txt | grep .c
main.c
utils.c
zmbash-2.5$