A simple UNIX shell implementation written in C, inspired by bash. This project recreates the functionality of a basic command-line interpreter with support for command execution, pipelines, redirections, environment variables, and built-in commands.
- Interactive prompt: Display a command prompt and wait for user input
- Command execution: Execute commands found in PATH or by absolute/relative path
- Argument handling: Pass arguments to executed commands
- Command history: Navigate through command history using arrow keys
<- Input redirection>- Output redirection (overwrite)>>- Output redirection (append)<<- Heredoc (read input until delimiter)
- Chain multiple commands using the pipe operator
| - Support for multiple pipes in a single command line
- Variable expansion with
$VARIABLE $?- Exit status of the last executed command- Quote handling:
- Single quotes
'- Preserve literal value - Double quotes
"- Allow variable expansion
- Single quotes
echo- Display text (with-nflag support)cd- Change directory (relative or absolute path)pwd- Print working directoryexport- Set environment variablesunset- Remove environment variablesenv- Display environment variablesexit- Exit the shell
Ctrl+C- Interrupt current commandCtrl+D- Exit shell (EOF)Ctrl+\- Quit (ignored in interactive mode)
- GCC or compatible C compiler
- Make
- readline library (development files)
sudo apt-get update
sudo apt-get install build-essential libreadline-devmakeThis will create the minishell executable.
make clean # Remove object files
make fclean # Remove object files and executable
make re # Rebuild everything./minishell# Simple command execution
minishell$ ls -la
# Pipelines
minishell$ cat file.txt | grep "pattern" | wc -l
# Redirections
minishell$ echo "Hello World" > output.txt
minishell$ cat < input.txt
minishell$ echo "Append text" >> output.txt
# Heredoc
minishell$ cat << EOF
> line 1
> line 2
> EOF
# Environment variables
minishell$ export MY_VAR="Hello"
minishell$ echo $MY_VAR
minishell$ echo "Exit status: $?"
# Built-in commands
minishell$ pwd
minishell$ cd /tmp
minishell$ env
minishell$ unset MY_VAR
minishell$ exit.
├── Makefile # Build configuration
├── minishell.h # Header file with all declarations
├── main.c # Entry point and main loop
├── execution/ # Command execution logic
│ ├── exec.c # Command execution
│ ├── pipeline.c # Pipeline handling
│ ├── redirection.c # I/O redirections
│ ├── heredoc.c # Heredoc implementation
│ ├── signals.c # Signal handling
│ └── built-in/ # Built-in commands
│ ├── echo.c
│ ├── cd.c
│ ├── pwd.c
│ ├── export.c
│ ├── env.c
│ ├── exit.c
│ ├── unset.c
│ └── builtin.c
├── parsing/ # Input parsing and tokenization
│ ├── lexer/ # Lexical analysis (tokenization)
│ ├── parser/ # Syntax parsing (AST construction)
│ ├── expansion.c # Variable expansion
│ └── env_parsing.c # Environment parsing
├── libft/ # Custom C library functions (string, memory utils)
└── src/ # Utility functions (error handling, memory management)
- All dynamically allocated memory is properly freed
- No memory leaks (verified with valgrind)
- Comprehensive error checking for system calls
- Meaningful error messages for user feedback
- Proper exit status handling and propagation
- Accessible via
$?variable
- mmounsif
- delhajou
This project is part of the 42 School curriculum. It provides hands-on experience with:
- Process management (fork, execve, wait)
- File descriptors and I/O redirection
- Signal handling
- Parsing and lexical analysis
- Memory management in C
This project is created for educational purposes as part of the 42 School curriculum.