A minimal POSIX‑like shell implemented in C as part of 42’s Minishell project. It supports a practical subset of bash(1) semantics, robust process management, and precise file descriptor and signal handling. The project includes both the mandatory requirements and the official bonus for logical operators with precedence.
- Mandatory: prompt + history (
readline), path resolution, redirections (<,>,>>,<<), pipelines (|), environment expansion$VAR, special$?, quotes (',"), and interactive signals (^C,^D,^\). - Bonus: logical operators
&&,||with parentheses for precedence. - Builtins:
echo -n,cd,pwd,export,unset,env,exit.
- Lexer with token classification (words, quoted words, operators, redirections, parentheses).
- Quote rules: single quotes do not expand; double quotes do expand
$. - Parameter expansion:
$[A-Za-z_][A-Za-z0-9_]*and$?. - Word splitting occurs after expansions in unquoted parameters, using spaces as separators (simplified Bash behavior).
- Binary AST for operators:
PIPE,AND_IF,OR_IF, with nodes forCMDand subshell nodes for(...)(bonus for precedence). - Redirections attached to command nodes and applied immediately before
execve. - Pipelines use
pipe()anddup2()to chainstdin/stdout, maintaining strict file descriptor hygiene. waitsemantics: the shell reports the last command status in a pipeline; logical operators depend on child statuses.
echo [-n]— handles-naccurately.cd [--] [dir]—HOMEfallback; errors on too many args; updatesPWD/OLDPWD.pwd— prints the current working directory usinggetcwd().export [KEY[=VALUE] ...]— validates identifiers; without arguments prints variables in alphabetical order.unset [KEY ...]— removes keys.env— prints environment variables without options.exit [n]— numeric parsing,too many argumentshandling,--as end‑of‑options.
<,>,>>— open/dup2/close handled with error checking.<<(heredoc) — reads until delimiter (history not updated). Signals handled gracefully during heredoc input.
- Parent (shell):
SIGINTprints a fresh prompt;SIGQUITignored. - Children:
SIGINT/SIGQUITrestored to default for standard command behavior (e.g.,catstopped by^C,Quit (core dumped)on^\). On signal termination,$? = 128 + signal.
- Expansion of undefined variables does not create or declare new environment entries; variables can only be created explicitly with export.
- Advanced parameter expansion:
${...},${var@Q},${#var}, etc. - Command substitution:
$(...)/ backticks. - Arithmetic expansion:
$(( ... )). - Bash‑specific quoting:
$'...',$"..."(gettext/ANSI‑C). - Job control (
fg,bg,jobs). - Globbing beyond the required scope (wildcards handled for current dir only when bonus enabled).
- Compiler:
clangwith-Wall -Wextra -Werror. - GNU Readline development headers.
- Make (provided Makefile targets:
all,clean,fclean,re,dev,debug).
The project adheres to the allowed‑functions constraint from the subject (
readline,fork/exec,dup/pipe, etc.).
sudo apt-get update && sudo apt-get install -y build-essential libreadline-devmake # or make debug, make dev
./miniyeska- Processes & pipelines: fork/exec, pipe, dup2, wait/waitpid.
- Descriptors: lifetime, error‑safe closing, redirection discipline.
- Signals: per‑process actions and terminal group management.
- Parsing: correct tokenization, AST, and operator precedence.
- Error handling and exceptional memory cleanup.
Authored by angelurano and g01100001

