Γcole 42 Minishell Project - A simple Unix shell implementation that mimics the basic features of Bash.
MiniShell is a Unix shell application developed as part of the Γcole 42 curriculum. This project aims to develop a deep understanding of system programming, process management, file descriptors, and parsing.
The project allows users to execute system commands through a command-line interface, use pipes and redirections, and manage environment variables.
- β Finding and executing commands from PATH
- β Relative and absolute path support
- β Command argument handling
- β
<- Input redirection - β
>- Output redirection (overwrite) - β
>>- Output redirection (append) - β
<<- Heredoc (read input until delimiter)
- β
Pipe (
|) support between multiple commands - β Unlimited pipe chains
- β File descriptor management between pipes
- β
Single quotes (
') - Ignore all metacharacters - β
Double quotes (
") - Ignore metacharacters except $ - β
Escape character (
\) support
- β
$VAR- Variable expansion - β
$?- Exit status of last command - β Variable expansion within double quotes
- β
Ctrl-C- SIGINT (terminate current command) - β
Ctrl-D- EOF (exit shell) - β
Ctrl-\- SIGQUIT (do nothing)
- GCC compiler
- GNU Make
- readline library
# Install readline on macOS
brew install readline
# Install readline on Linux
sudo apt-get install libreadline-dev# Clone the repository
git clone [repository-url] minishell
cd minishell
# Compile
make
# Clean
make clean # Remove object files
make fclean # Remove all compiled files
make re # Recompile# Start MiniShell
./minishell
# Shell is running
MiniShell$ echo "Hello World"
MiniShell$ ls -la | grep minishell
MiniShell$ cat < input.txt > output.txt
MiniShell$ export MY_VAR=42
MiniShell$ echo $MY_VARPrints text to the screen. The -n flag suppresses the newline character.
echo Hello World
echo -n "No newline"Changes the current working directory.
cd /path/to/directory
cd ..
cd ~
cd # Goes to HOME directoryPrints the current working directory.
pwdCreates or updates environment variables.
export VAR=value
export PATH=/usr/bin:$PATH
export # List all exported variablesRemoves environment variables.
unset VARLists all environment variables.
envExits the shell. Optional exit code can be specified.
exit
exit 42- All dynamic memory allocations are properly freed
- Valgrind can be used for memory leak checking
- Temporary memory cleanup after each command
- Creating child processes with
fork() - Executing commands with
execve() - Process tracking with
waitpid() - Process synchronization for pipes
- Tokenization and lexical analysis
- Parsing within and outside quotes
- Special character handling
- Syntax error checking
- Appropriate messages for syntax errors
- Command not found (127)
- Permission denied errors
- Exit status codes
minishell/
βββ main.c # Main program loop and signal management
βββ Makefile # Compilation configuration
βββ include/
β βββ minishell.h # Header file and struct definitions
βββ built-in/ # Built-in commands
β βββ built-in.c # Built-in dispatcher
β βββ cd.c # cd command
β βββ echo.c # echo command
β βββ env.c # env command
β βββ exit.c # exit command
β βββ export.c # export command
β βββ pwd.c # pwd command
β βββ unset.c # unset command
βββ execute/ # Command execution
β βββ add_pipes.c # Pipe structure creation
β βββ execute_command.c # Command execution
β βββ next_process.c # Pipe chain management
β βββ redir_execute.c # Redirection execution
βββ init_and_find_path/ # Initialization and PATH
β βββ find_env.c # Environment variable lookup
β βββ find_path.c # Command search in PATH
β βββ ms_init.c # Shell initialization
βββ redirections/ # Redirection operations
β βββ redir_heredoc.c # Heredoc processing
β βββ redir_order.c # Redirection ordering
β βββ redir_run.c # Redirection execution
β βββ redir_set.c # Redirection setup
βββ syntax/ # Parsing and syntax
β βββ add_cmd.c # Command token processing
β βββ dollar_parse.c # Variable expansion
β βββ quate_parse.c # Quote handling
βββ libft/ # Utility function library
βββ ft_split.c
βββ ft_strjoin.c
βββ ... (other utility functions)
MiniShell$ ls -la
MiniShell$ cat file.txt
MiniShell$ grep "pattern" file.txtMiniShell$ ls -la | grep minishell | wc -l
MiniShell$ cat file.txt | grep "error" | sort | uniqMiniShell$ echo "Hello" > output.txt
MiniShell$ cat < input.txt > output.txt
MiniShell$ ls -la >> log.txtMiniShell$ cat << EOF
> Line 1
> Line 2
> EOFMiniShell$ export NAME="John"
MiniShell$ echo "Hello $NAME"
MiniShell$ echo "Exit code: $?"MiniShell$ echo 'Single quotes: $USER'
MiniShell$ echo "Double quotes: $USER"
MiniShell$ echo "Mixed 'quotes' work"MiniShell$ < input.txt grep "error" | sort | uniq > output.txt
MiniShell$ export PATH=/bin:/usr/bin && ls | wc -lThroughout this project, in-depth knowledge was gained in the following topics:
- System Programming: Fork, exec, wait system calls
- Process Management: Creating and managing child processes
- Pipes and IPC: Inter-process communication
- File Descriptors: FD management with dup2, close
- Signal Handling: SIGINT, SIGQUIT management
- Parsing: Lexical analysis and tokenization
- Memory Management: Malloc, free and leak prevention
- UNIX Shell: Understanding Bash behavior
- Wildcard (*) expansion is not supported
- History navigation (up/down arrows) is limited
- Job control (bg, fg, jobs) is not supported
- Subshells (parentheses usage) are not supported
- Logical operators (&&, ||) are not supported
This project is part of the Γcole 42 curriculum and was developed for educational purposes.
- bkas - Developer
- melihyil - Developer
Γcole 42 | Minishell Projesi | 2024