A mimic of bash built as part of the 42 Prague curriculum in C.
├── Lexical Analysis (lexus/)
│ ├── tokenise.c → Token creation and management
│ ├── lexer.c → Main lexical analyser
│ ├── quotes.c → Quote handling ('single', "double")
│ ├── dollar.c → Environment variable expansion ($VAR, $?)
│ └── operators.c → Pipe and redirection operators
│
├── Execution Engine (execute/)
│ ├── execute.c → Command execution coordinator
│ ├── builtins.c → Built-in command dispatcher
│ ├── heredoc.c → Here-document implementation
│ └── redirections.c → I/O redirection handling
│
├── Process Management
│ ├── processes.c → Fork/exec/wait handling
│ ├── piping.c → Multi-pipe coordination
│ └── signal.c → Signal management (SIGINT, SIGQUIT)
│
└── Built-ins (builtins/)
├── cd.c → Directory navigation + PWD/OLDPWD
├── export.c → Environment variable management
├── echo.c → Text output with -n flag
└── env_pwd_exit.c → Environment display and exit handling
- Lexical analysis: Tokenises input with quote handling, variable expansion, and operator recognition
- Piping: Multi-stage pipeline execution with proper file descriptor management
- Redirections: Input (
<), output (>), append (>>), and here-documents (<<) - Variable expansion: Environment variables (
$VAR) and exit status ($?) - Built-in commands:
cd,echo,pwd,export,unset,env,exit - Signal handling: Proper SIGINT/SIGQUIT handling in interactive and non-interactive modes
- Command history: Readline integration with history persistence
minishell> export SEARCH_TERM="minishell"
minishell> echo "Finding all files containing: $SEARCH_TERM" > search_log.txt
minishell> ls -la src/ | grep "\.c$" | head -5 >> search_log.txt
minishell> cat << DELIMITER
This is a test file for minishell
Testing variable expansion: $SEARCH_TERM
Another line with $PWD directory
Final line of input
DELIMITERStep-by-step execution:
-
Variable export (
export.c):handle_export()setsSEARCH_TERM=minishellin environment- Updates
prompt->env_copywith new variable
-
Variable expansion and output redirection (
dollar.c,redir_handlers.c):dollar()function expands$SEARCH_TERMto "minishell"output_redirection()creates/truncatessearch_log.txt- Echo output: "Finding all files containing: minishell" written to file
-
Pipeline (
piping.c):split_tokens()separates three commands:ls -la src/|grep "\.c$"|head -5piping()creates child processes with pipe coordination- Stage 1:
ls -la src/lists source directory contents - Stage 2:
grep "\.c$"filters only .c files - Stage 3:
head -5takes first 5 results
-
Append redirection:
append_redirection()openssearch_log.txtwith O_APPEND flag- Pipeline output appended to existing file content
-
Heredoc processing (
heredoc.c):handle_heredoc()creates temporary file/tmp/filename_tempwrite_to_tmp()reads lines until "DELIMITER" encountered- Each line processed for variable expansion (
$SEARCH_TERM,$PWD) - Heredoc content displayed directly to stdout (no pipe)
-
Process management (
processes.c,pipe_utils.c):- Each pipeline command runs in separate child process
wait_for_children()ensures proper cleanup- File descriptors properly managed between pipeline stages
- Exit status tracking through
g_received_sig
Built by Yeva Husieva & Viacheslav Moroz