minishell is a C project that implements a small Unix-like shell with parsing, expansion, redirections, pipelines, and command execution.
This codebase also parses and executes logical operators (&&, ||) and parenthesized command groups.
- Interactive shell loop with
readlinehistory support. - Non-interactive mode (commands can be piped to stdin).
- Builtins:
cd,pwd,echo,env,export,unset,exit. - Environment variables stored in an internal linked list.
- Variable expansion (
$VAR,$?) and expansion inside double-quoted strings. - Redirections:
<,>,>>,<<(heredoc). - Pipelines built around
fork,pipe,dup2, andexecve. - Wildcard expansion for
*against entries in the current directory (dotfiles only when the pattern starts with.). - Logical operators
&&,||, and parenthesized command groups.
- The main loop reads a line, initializes runtime state, and dispatches parsing/execution.
- The parser tokenizes input into a linked list (
t_word) and runs syntax checks (pipes, redirections, logic tokens, parenthesis). - Pre-execution steps handle heredocs, variable expansion, wildcard expansion, and token joins.
- Execution chooses between builtin dispatch in-process and external commands via
fork+execve, with redirections/pipes applied through fd duplication. - Exit status is tracked globally and reused by conditional execution.
cc(C compiler)makereadlinedevelopment/runtime library
makeOther available targets:
make clean
make fclean
make reThe build produces the executable:
./minishellInteractive mode:
./minishellNon-interactive mode:
printf 'echo hello_from_minishell\nexit\n' | ./minishell./minishell
echo "User: $USER"
ls -la | grep src > out.txt
cat out.txt
exitTested non-interactive smoke example output:
hello_from_minishell
include/
minishell.h # Core types, tokens, prototypes
libft/ # Internal 42 utility library
src/
main/ # Shell loop, prompt, signal setup
env/ # Environment linked-list management
parsing/ # Tokenization and syntax checks
expand/ # Variable and wildcard expansion
exec/ # Heredoc prep, redirections, pipelines, execution
builtins/ # Builtin command implementations
free_and_exit/ # Cleanup and exit utilities
git/ # Prompt git branch/dirty-state helpers
tester/ # Local test scripts/assets
Makefile
- Designing a shell around linked-list based token streams and explicit execution phases.
- Implementing process orchestration with
fork,execve, pipes, redirections, and wait status handling. - Building parsing/syntax checks for shell grammar edge cases.
- Managing shell state (environment, exit code, signals, heredoc behavior) consistently across parent and child processes.