A minimal Unix shell implementation in C, developed as part of the 42 school curriculum. minishell aims to replicate the basic behavior of bash, supporting command execution, pipelines, redirections, environment variables, and several built-in commands.
- Prompt: Displays a customizable prompt and reads user input.
- Command Execution: Runs binaries from the system's
$PATHand supports argument passing. - Built-in Commands: Implements the following built-ins:
echocdpwdexportunsetenvexit
- Pipelines: Supports chaining commands with
|. - Redirections: Handles input
<, output>, append>>, and heredoc<<. - Environment Variables: Expands variables (e.g.,
$HOME) and manages the shell environment. - Quotes: Handles single
'and double"quotes for grouping and variable expansion. - Signal Handling: Manages
Ctrl+C,Ctrl+D, andCtrl+\gracefully. - Error Handling: Provides informative error messages for invalid commands, syntax errors, and failed operations.
- Memory Management: Cleans up all allocated resources to avoid leaks.
- GNU Make
- GCC or Clang
readlineandncurseslibraries
makeThis will compile the shell and its dependencies (including a custom libft).
./minishellYou'll see a prompt where you can type commands as in a regular shell.
A Dockerfile is provided for building and running minishell in a containerized environment:
docker build -t minishell .
docker run -it minishell- Type commands and press Enter to execute.
- Use pipes (
|) to chain commands. - Redirect input/output using
<,>,>>, and<<. - Use built-in commands for shell management.
- Press
Ctrl+Dto exit the shell.
ls -l | grep minishell > result.txt
export MYVAR=42
echo $MYVAR
cat << EOF
Hello minishell!
EOFsrc/— Core shell logic (parsing, execution, environment, signals, etc.)builtins/— Implementations of built-in commandslibft/— Custom standard library functionsget_next_line/— Line reading utilityincl/— Header files
- Valeria Harkusha
- Yen Nguyen
- This project is a learning exercise and may not cover all edge cases or advanced shell features.
- Memory management is a work in progress; some leaks may remain.
This project is for educational purposes and is not intended for production use.