Skip to content
kchaoukiPublic

About

A Unix shell implementation in C, built as part of the 42 school curriculum. Minishell replicates core Bash behavior including command execution, pipelines, redirections, environment variable expansion, and built-in commands.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

minishell

A Unix shell implementation in C, built as part of the 42 school curriculum. Minishell replicates core Bash behavior including command execution, pipelines, redirections, environment variable expansion, and built-in commands.

Authors

  • kchaouki
  • rrhnizar

Features

Mandatory

  • Interactive prompt with command history (via GNU Readline)
  • Command execution with PATH resolution
  • Single and double quote handling
  • Environment variable expansion ($VAR, $?)
  • Input/output redirections: <, >, >>
  • Here-doc (<<)
  • Pipes (|)
  • Signal handling: Ctrl+C, Ctrl+D, Ctrl+\

Bonus

  • Logical operators: && and || with parentheses for grouping
  • Wildcard expansion (*) in the current directory
  • Subshell execution

Built-in Commands

Command Description
echo Print text (-n flag supported)
cd Change directory (absolute/relative paths)
pwd Print working directory
export Set or display environment variables
unset Remove environment variables
env Print environment
exit Exit the shell with a status code

Project Structure

minishell/
├── minishell.c          # Entry point, main loop, signal handling
├── minishell.h          # Global header and struct definitions
├── minishell_utils.c    # Utility functions
├── all_free.c / all_free2.c  # Memory cleanup
├── parsing/
│   ├── parser.c         # Main parser
│   ├── create_tokens.c  # Tokenizer
│   ├── global_split.c   # Input splitting
│   ├── here_doc.c       # Here-doc handling
│   ├── define_mandatory.c / define_bonus.c
│   ├── synt_error_mandatory.c / synt_error_bonus.c
│   └── analyzer/        # Syntax analysis and error detection
├── execution/
│   ├── exec_commands.c  # Command dispatching
│   ├── exec_cmd.c       # Command execution
│   ├── pipe.c           # Pipe creation and management
│   ├── redirections.c   # Redirection setup
│   ├── and_or.c         # `&&` / `||` logic
│   ├── subshell.c       # Subshell execution
│   ├── wildcard.c       # Wildcard expansion
│   ├── builtins/        # Built-in command implementations
│   └── expention/       # Variable and redirection expansion
└── libft/               # Custom C standard library

Requirements

  • GCC with -Wall -Wextra -Werror
  • GNU Readline library

On macOS (using Homebrew):

brew install readline

Building

# Mandatory version
make

# Bonus version (&&, ||, subshells, wildcards)
make bonus

# Clean object files
make clean

# Full clean (removes binaries)
make fclean

# Rebuild
make re

Note: The Makefile is configured with a specific Readline path (/goinfre/kchaouki/brew/opt/readline). You may need to update the RDL and include path in the Makefile to match your local Readline installation.

Usage

./minishell
./minishell_bonus   # bonus version

Once running, the shell presents a minishell ~ prompt and accepts commands just like Bash.

Examples

minishell ~ echo "Hello, World!"
minishell ~ ls -la | grep .c
minishell ~ export MY_VAR=42 && echo $MY_VAR
minishell ~ cat << EOF
minishell ~ pwd > output.txt
minishell ~ exit 0

Notes

  • Only one global variable is used (g_r) to store the signal state, in compliance with 42 school norms.
  • All allocated memory is freed before exit.
  • The shell handles Ctrl+C by displaying a new prompt, Ctrl+D by exiting cleanly, and Ctrl+\ is ignored (matching Bash behavior).

About

A Unix shell implementation in C, built as part of the 42 school curriculum. Minishell replicates core Bash behavior including command execution, pipelines, redirections, environment variable expansion, and built-in commands.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages