Minishell is a simplified shell project developed as part of the 42 School curriculum. The aim of the project is to create a functional shell that mimics some of the core behaviors of popular shells like bash, while providing a solid foundation for learning about process management, input/output redirection, pipes, and system calls in UNIX-based systems.
The project focuses on replicating the basic functionalities of a shell without any bonus features, keeping the implementation minimal and adhering to specific requirements. The project encourages you to explore low-level system programming in C, making use of system calls such as fork(), execve(), pipe(), and signals handling.
The following functionalities are implemented:
-
💻 Prompt display:
- A prompt is displayed where the user can enter commands.
-
⚙️ Command execution:
- The shell can execute binary commands located in
$PATH, similar to/bin/lsor/usr/bin/cat.
- The shell can execute binary commands located in
-
🔧 Built-in commands:
- The shell implements a few essential built-in commands:
echowith the-noption.cdfor changing the current directory.pwdto print the current working directory.exportto set environment variables.unsetto remove environment variables.envto display the environment variables.exitto terminate the shell.
- The shell implements a few essential built-in commands:
-
🌐 Environment variable handling:
- The shell manages environment variables and allows manipulation using built-in commands like
exportandunset.
- The shell manages environment variables and allows manipulation using built-in commands like
-
📄 Redirections:
- Supports input (
<) and output (>,>>) redirections for commands.
- Supports input (
-
🔗 Pipes:
- Implements pipes (
|), enabling command chaining by sending the output of one command to the input of another.
- Implements pipes (
-
🚨 Signal handling:
- Handles signals for
Ctrl+C,Ctrl+D, andCtrl+\to behave like a normal shell:Ctrl+C: Sends an interrupt signal, should not terminate the shell.Ctrl+D: Closes the shell when the input is empty.Ctrl+\: Should do nothing.
- Handles signals for
-
❗ Error handling:
- Proper error messages are displayed for invalid commands, file access issues, or command execution problems.
The following bonus functionalities are not included in this version:
- Logical operators (
&&,||).
- Language: C (with allowed standard libraries such as
unistd.h,fcntl.h,stdio.h,signal.h, etc.) - Operating System: Linux-based (preferably tested on macOS or Linux).
- Compiler:
ccwith the following flags:-Wall -Wextra -Werror
To compile and test Minishell, follow these steps:
- Clone the repository:
git clone git@github.com:AnnLvu/minishell_42.git cd minishell_42
make # Compiles the minishell library ⚒️
./minishell # Run the shell
make clean # Cleans up object files 🧹
make fclean # Full cleanup of generated files 🧼
make re # Rebuild everything from scratch 🔄# Running a command in $PATH
ls -l
# Redirection
cat < input.txt > output.txt
# Piping
ls | grep minishell
# Built-ins
pwd
export VAR=value
echo $VAR
unset VAR
env
exitThis project provides a basic yet functional shell that introduces you to the inner workings of a command-line interface, process control, and system-level programming. Through the implementation of minishell, you'll gain a deep understanding of how shells work at the fundamental level, focusing on essential UNIX system calls and process management.