This project has been created as part of the 42 curriculum by ydylan-k, sming-zh.
Minishell is a 42 project aimed at creating a minimal yet fully functional shell based on Bash. The primary goal of this project is to understand core system architecture by building it from scratch, specifically focusing on Lexical Analysis, Process Management, Inter-Process Communication (IPC), Environment Management, Signal Handling.
libreadline-devis used to await and read for user input. It's prefixed with:3.- Mandatory Built-ins:
echo: Prints text into standard output followed by a line break. Prepend with-nflag to disable line break.:3 echo hello hello :3 echo -n hello hello:3 echo hello hello :3
cd: Changes current working directory to anotherpwd: Shows current working directoryexport: Shows or creates an environment variable with format<key>=<value>:3 export six=seven :3 echo $six seven :3 export declare -x six="seven" :3
unset: Deletes an environment variableenv: Shows all shell variablesexit: Exits current shell with optional exit code
- Quote Interpretation:
'(Single Quotes): Prevents the shell from interpreting meta-characters (literal string)."(Double Quotes): Prevents the shell from interpreting meta-characters, except for$(allows variable expansion).- Redirections:
<: Redirects terminal input from a specified file.>: Redirects terminal output to a specified file (truncates).<<(Heredoc): Reads multi-line input from the terminal until a specified delimiter is seen.>>: Redirects terminal output to a specified file in append mode.
- Pipelines (
|): Connects the output of one command directly into the input of the next using precise file descriptor management. - Environment Variables: Expands variables (e.g.,
$USER) and handles$?, which dynamically expands to the exit status of the most recently executed foreground pipeline. - Signal Handling: Custom behavior for
Ctrl+C(SIGINT),Ctrl+\(SIGQUIT), andCtrl+D(EOF) depending on whether the shell is in an interactive prompt, reading a heredoc, or executing a blocking command. - Wildcard Expansion (
*): Scans your directory to replace*patterns with real filenames. It ignores hidden files, won't expand if inside quotes, and keeps the pattern if no files match.
Minishell requires
libreadline-devwhich can be downloaded from your operating system's package manager.
- Run
make allto compile the program. make cleanto remove the object files.make fcleanto remove both the binary and the object files.make retomake fcleanandmake allagain.
./minishell
:3 echo hello
hello
:3 ls -a
. .. minishell
:3 exit
exit- Precedence climbing
- Shunting yard algorithm
- Shell grammar for recursive descent parser
- Parsing with recursive descent
- Shell Operation
- Abstract Syntax Tree
- Pipe buffer limit
- Heredoc deep dive
- O_TMPFILE
- GNU Readline Library
- Readline usage tutorial
- Readline: getting a new prompt on SIGINT
- Dangers of global and static variables
- Readline signal handling
- Double prompt issue
- Readline to original state when receiving SIGINT
- Subshell
- Visual Studio Code sigaction not defined
- Git Gud
- getcwd() Manpage
- history Manpage
- add_history()
- Readline dependency issue
The usage of AI in this project was used for all parts of this project. Like brainstorming and understanding data structure, execution pipeline, pipes, redirection, file descriptor handling, refactoring code, documentations, wildcard solving, and writing documentations.