This project has been created as part of the 42 curriculum by kraksana, mserovat.
Minishell is a small interactive Unix shell written in C as part of the 42 curriculum. Its goal is to explore how a shell reads and interprets commands, creates processes, connects file descriptors, and manages environment variables, signals, and dynamically allocated memory.
The project implements the mandatory part of the Minishell subject, version 10.0, using Bash as the reference for the required behavior.
- An interactive prompt and command history using GNU Readline.
- Command execution through
PATH, relative paths, or absolute paths. - Single and double quotes, environment variable expansion (
$VAR), and the last foreground pipeline status ($?). - Field splitting for unquoted variable expansions and preservation of quoted arguments, including empty strings.
- Input (
<), output (>), append (>>), and heredoc (<<) redirections. - Pipelines connecting multiple commands.
- Builtins:
echowith-n,cd,pwd,export,unset,env, andexit. - Logical working-directory tracking for
cd,pwd,PWD, andOLDPWD, including paths containing symbolic links. - Signal handling at the prompt, during command execution, and during heredoc collection. The only global variable stores a received signal number.
This submission contains the mandatory part only. It does not implement the bonus
operators && and ||, parenthesized command groups, or wildcard expansion.
Command substitution, shell scripting, semicolon command separators, and
backslash escaping are outside the implemented scope. Unclosed quotes produce a
syntax error instead of requesting continuation input.
- A C compiler available as
cc. - Make.
- GNU Readline headers and library.
On macOS with Homebrew, install Readline if it is not already installed:
brew install readlineThe Makefile automatically detects the Readline installation with
brew --prefix readline. On Linux, install the GNU Readline development package
provided by your distribution.
Run the following command from the project root, where the main Makefile is
located:
makeThe Makefile builds the bundled library through libft/Makefile, then creates
the minishell executable using cc -Wall -Wextra -Werror. Running make again
without source changes does not relink the executable.
| Command | Action |
|---|---|
make or make all |
Build the library and executable |
make clean |
Remove project and library object files |
make fclean |
Remove object files, libft.a, and the executable |
make re |
Clean and rebuild the project |
./minishellEnter commands at the minishell$ prompt. When pasting examples, enter one
command at a time and wait for the prompt to return.
echo "Hello, Minishell!"
export MESSAGE="hello world"
echo "$MESSAGE"
echo "$MESSAGE" | cat | wc -c
echo first > example_output.txt
echo second >> example_output.txt
cat < example_output.txt
unset MESSAGETo use a heredoc, enter the opening command, each body line, and the delimiter on separate lines:
cat << END
Hello $USER
ENDAn unquoted delimiter allows variable expansion in the body. Quoting the
delimiter, as in cat << 'END', preserves the body without variable expansion.
| Context | Key | Behavior |
|---|---|---|
| Empty or partially typed prompt | Ctrl+C | Clear the input and display a new prompt |
| Empty prompt | Ctrl+D | Exit the shell |
| Prompt | Ctrl+backslash | Ignore the signal |
| Running external command | Ctrl+C / Ctrl+backslash | Use the command's default signal behavior |
| Heredoc input | Ctrl+C | Cancel collection and the pending command; set status to 130 |
Use echo $? immediately after a command to inspect its status. Use exit to
leave the shell, or exit 42 to return a specific status to the calling shell.
Builtins run in the main shell for a standalone command and in child processes
when they are part of a pipeline.
If Norminette is installed, run it from the project root:
norminetteBehavior can be checked against Bash with the same commands and environment.
Interactive signals, heredocs, memory cleanup, and error cases should also be
reviewed before peer evaluation. Optional review reports and testing scripts
distributed in a separate verification/ folder are not build dependencies and
are not required in the submitted repository.
- The supplied 42 Minishell subject, version 10.0, and its evaluation checklist.
- GNU Bash Reference Manual for quoting, expansion, pipelines, redirections, and builtin behavior.
- GNU Readline documentation for input editing, history, and terminal interaction.
- Homebrew Readline formula for installing GNU Readline on macOS.
- Local system manual pages, available through
man:fork(2),execve(2),pipe(2),dup2(2),waitpid(2),sigaction(2),open(2),chdir(2),getcwd(3), andstat(2).
This project was developed collaboratively by kraksana and mserovat. AI was used as a learning and development aid to explain shell concepts, discuss design choices, and support understanding of parsing, expansion, process execution, file descriptors, signals, and memory management.
AI also assisted with code review, test design, debugging, and targeted code corrections, including heredoc handling, variable expansion, pipeline cleanup, allocation-failure handling, and directory tracking.
The implementation was checked through Bash comparisons, Norminette, automated tests, and manual checks. Both authors remain responsible for reviewing the changes, understanding the final code, and explaining its behavior during peer evaluation.