MSH (mini shell) - project analysis
Overview
- This project implements a small interactive Unix-like shell in pure C.
- It is built around the C standard library, POSIX system calls, GNU Readline, and a local libft utility library.
- The final executable name is `minishell`.
High-level execution flow
1. `msh.c` initializes shell state (environment copy and shell path).
2. It enters a REPL loop using `readline("> ")`.
3. User input is tokenized (`src/tokenizer`), parsed into an AST (`src/parser`), and executed (`src/exec`).
4. Command status is stored/retrieved through utilities in `src/utils/status.c`.
Main components
- `src/tokenizer/`
- Splits input into tokens (words, pipes, redirections, heredoc operators).
- Handles quote-aware word extraction and basic syntax checks for unclosed quotes.
- `src/parser/`
- Converts token lists into command/pipe AST nodes.
- Builds command nodes with arguments and redirection metadata.
- Provides AST analysis and cleanup helpers.
- `src/expander/`
- Expands environment variables.
- Handles quote processing and text transformation before execution.
- `src/heredoc/`
- Implements heredoc collection and related signal behavior.
- `src/exec/`
- Executes command ASTs, including pipelines.
- Applies redirections and runs external commands via an execvp-style wrapper.
- Manages process creation (`fork`, `pipe`, `dup2`, `wait`) and exit status propagation.
- `src/builtins/`
- Built-in commands: `cd`, `export`, `env`, `unset`, `pwd`, `echo`, `exit`.
- Distinguishes builtins that must run in the parent shell process (state-changing operations) from child-process execution.
- `src/utils/`
- Signal setup for interactive behavior.
- Environment list helpers and path handling.
- Global status getter/setter.
- `libc/`
- Local libft-style helper library (string/list/memory helpers) built as `libft.a`.
Build and run
- Build:
- `make`
- Run:
- `./minishell`
- Clean:
- `make clean`
- `make fclean`
- `make re`
Dependencies
- C compiler (`cc`)
- GNU Readline development library (`-lreadline`)
- POSIX environment (Linux/macOS-like system calls)
Notes
- Input history is enabled through Readline (`add_history` in parser entry).
- The shell includes custom signal handling for interactive usage and heredoc mode.
- The Makefile includes a `valgrind` target for memory/debug checks.