Minishell is a simple command-line interpreter project inspired by bash. It provides an opportunity to understand how shells work by implementing fundamental features such as command parsing, execution, piping, redirections, and signal handling. Through this project, you’ll gain a deeper understanding of processes, file descriptors, and memory management in C.
The purpose of this project is to:
- Learn about process management in Unix systems.
- Understand how shells handle commands, pipelines, and redirections.
- Explore file descriptor management for input/output redirection.
- Implement signal handling and built-in shell commands.
- Adhere to strict coding norms and minimize memory leaks.
This project challenges you to replicate essential functionalities of a shell, equipping you with knowledge that applies to various areas of systems programming.
-
Interactive Shell Prompt:
- Display a prompt when waiting for user input.
- Handle
ctrl-C,ctrl-D, andctrl-\to mimic bash behavior:ctrl-C: Displays a new prompt on a new line.ctrl-D: Exits the shell.ctrl-\: Does nothing.
-
Command Execution:
- Search and execute commands using the
PATHenvironment variable or relative/absolute paths.
- Search and execute commands using the
-
Quotes Handling:
- Single quotes (
'): Prevent interpretation of metacharacters within. - Double quotes (
"): Prevent interpretation except for$(dollar sign).
- Single quotes (
-
Redirections:
<: Redirect input.>: Redirect output.<<: Here-document with a delimiter.>>: Redirect output in append mode.
-
Pipes:
- Implement pipelines (
|), connecting the output of one command to the input of the next.
- Implement pipelines (
-
Environment Variables:
- Handle
$for variable expansion. - Handle
?to expand the exit status of the last executed command.
- Handle
-
Built-in Commands:
echowith-noption.cdwith relative or absolute paths.pwdwith no options.exportwith no options.unsetwith no options.envwith no options or arguments.exitwith no options.
-
Memory Management:
- Ensure proper cleanup of heap-allocated memory. No memory leaks allowed in your code.
- Implement logical operators (
&&and||) with parentheses for precedence. - Wildcard (
*) handling for the current directory.
Note: Bonus features will only be evaluated if all mandatory requirements are met perfectly.
- Code must be written in C and follow the 42 Norm.
- Use only allowed external functions (e.g.,
readline,printf,fork,execve,pipe). - Use a single global variable, limited to signal number storage.
- Manage all errors gracefully (no segmentation faults, bus errors, etc.).
- Use a Makefile with the following rules:
all,clean,fclean,re, andbonus.
- If using
libft, include its source code and Makefile in alibft/folder.
- Avoid interpreting unclosed quotes or unsupported special characters like
\or;. - Stick strictly to the subject's requirements and use bash as a reference for doubts.
-
Initialize the Project:
- Set up the repository and include necessary files (
Makefile,.h,.c). - Include
libftif needed.
- Set up the repository and include necessary files (
-
Implement the Shell Core:
- Create a loop to display a prompt and wait for user input.
- Parse commands and handle syntax errors.
-
Add Command Execution:
- Implement searching for executables in
PATH. - Execute commands using
forkandexecve.
- Implement searching for executables in
-
Handle Quotes and Redirections:
- Parse single and double quotes properly.
- Add support for
<,>,<<, and>>redirections.
-
Implement Pipes:
- Create pipelines using
pipe()to link commands.
- Create pipelines using
-
Add Built-in Commands:
- Implement built-ins like
echo,cd,pwd, etc., according to specifications.
- Implement built-ins like
-
Handle Signals:
- Capture and handle signals (
SIGINT,SIGQUIT, etc.) to mimic bash behavior.
- Capture and handle signals (
-
Memory Management:
- Ensure all heap allocations are freed and avoid memory leaks.
-
Bonus Features (if applicable):
- Implement
&&,||, and wildcard handling.
- Implement
Run the following command to compile the project:
makeThis project was developed by me together with my friend, Eleni. She made major contributions by:
- Parsing the input data and preparing it for execution
- Handling errors and edge cases
- Implementing the built-in commands
Her work was essential to the success of this project!
