Untitled
d2
Pauline (Kid_P)
🌐Blueprint
This minishell should have the characteristics of a specific shell. We will use bash as a reference. Functions are written with readability, scalability, modularity and overall robustness in mind.
Main Loop
- [x] Setup infinite loop with
readline(prompt)
- [x] infinite loop must take
env as argument
- [x] Handle Ctrl-D (EOF) to exit
- [x] Add input line to history (
add_history)
- [x] Forward input to tokenization and AST pipeline
- [x] Provide lookup function for
$VAR expansion
Import Environment Variables
- [x] Copy
envp into linked
- [x] SHLVL needs to be updated by +1 after import
- [x] Store
key and value separately
Tokenize Input
- [x] Split input into
char **tokens
- [x] Handle quotes correctly to group multi-word arguments
- [x] Preserve special characters for redirections/pipes
Validate Syntax - Lexer
- [x] Check for unclosed quotes
- [x] Validate pipe
| positions
- [x] Check redirection operators
<, >, >>, << have targets
- [x] Reject unsupported characters (
\\\\, ;)
- [x] Ignore empty input lines
Expand Environment Variables
- [x] Loop through tokens
- [x] Replace
$VAR with value from environment
- [x] Replace
$? with last command exit status
- [x] Respect quotes: single
'...' no expansion, double "..." expand
- [x] Free old token strings and malloc new ones as needed
Quote trimming
Setup Signal Handlers
- [x] Handle Ctrl-C (
SIGINT) → new prompt
- [x] Handle Ctrl-D → exit shell
- [x] Handle Ctrl-\ (
SIGQUIT) → ignore
- [x] Ensure signals behave correctly during child process execution
Implement Built-ins
- [x] Implement
cd → change current directory
- [x] Implement
echo → print arguments
- [x] Implement
pwd → print working directory
- [x] Implement
export → add/update environment variable
- [x] Allow insertion for
export if args given
- [x] print export list if no args given
- [x] sort export list before printing
- [x] handle append to value
KEY+=123 which appends 123 to the existing value of KEY
- [x] Implement
unset → remove environment variable
- [x] Implement
env → print all environment variables
- [x] Implement
exit → exit shell with optional status
- [x] Create builtin[] table mapping names → function pointers
Build AST
- [x] Convert token array into AST nodes
- [x]
NODE_COMMAND → store command + args
- [x]
NODE_PIPE → left/right children
- [x]
NODE_REDIR → operator + target file
- [x] Ensure tree correctly represents command structure
Execute AST
- [x] Traverse AST recursively
- [x] For
NODE_COMMAND: check if builtin → call implemented function
- [x] If not builtin →
execve() external command
- [x] execute_external_commands()
- [x] Handle pipes correctly
- [x] Handle redirections (
<, >, >>, <<)
- [x] Apply signal behavior during execution
Cleanup & Loop Back
- [x] Free AST nodes
- [x] Free token arrays
- [x] Return to main loop and prompt for next input
📖 git - how to
Git conventional commits cheatsheet
Pull Request
Validating (Merging) a Pull Request
Creating a New Branch
Cherry-Pick
📚Resources
Task Rabbit
minishell error code standardization proposal
📋minishell edge cases
valgrind .supp file to ignore leaks from readline library