<
<html>
  <head>
    <title>Minishell</title>
  </head>
function buildAmazingProject() {
  const innovation = true;
  return success;
}
git commit -m "feat: 42 Abu Dhabi Project"
git push origin main
🚀 Deployment successful!
// Clean, maintainable code
const result = await deploy();
console.log('Project live! 🎉');
01001000 01100101 01101100 01101100 01101111
01010111 01101111 01110010 01101100 01100100
01000011 01101111 01100100 01100101
01001001 01101110 01101110 01101111 01110110 01100001 01110100 01100101
01000010 01110101 01101001 01101100 01100100
01000100 01100101 01110000 01101100 01101111 01111001
01010011 01110101 01100011 01100011 01100101 01110011 01110011
$ npm run build
</> Code
{
}
</>
42 Abu Dhabi Project

Minishell

Unix Shell Implementation

Scroll to explore

Project Overview

In the Minishell project at 42 school, I developed a simplified version of a Unix shell. This involved implementing various functionalities like executing commands, managing environment variables, handling signals, and performing input/output redirection. By creating Minishell, I gained hands-on experience in system programming and process management within Unix/Linux environments. This project challenged me to design an efficient and user-friendly command-line interface while adhering to Unix shell standards and conventions.

2 months
Development Time
2
Team Size
Minishell - Project Screenshot showcasing technical implementation

Technology Stack

Cutting-edge technologies and tools that power this project

C

Core Programming Language

Unix System Calls

System Programming

Process Management

Process Control

Signal Handling

Signal Management

File Descriptors

I/O Redirection

Stack Overview

This project leverages a modern tech stack combining 5 powerful technologies to deliver exceptional performance, scalability, and user experience.

Key Features

Innovative features that make this project stand out from the crowd

Command Execution

Execute system commands and programs with proper argument parsing, PATH resolution, and process creation using fork and exec system calls.

Learn more

I/O Redirection

Complete implementation of input/output redirection with support for <, >, >>, and | operators for flexible command chaining and file operations.

Learn more

Built-in Commands

Implementation of essential shell built-ins including echo, cd, pwd, export, unset, env, and exit with proper option handling and error management.

Learn more

Signal Handling

Proper signal management for SIGINT, SIGQUIT, and SIGTERM with appropriate signal handling for both shell and child processes.

Learn more

Environment Variables

Complete environment variable management with support for variable expansion, modification, and inheritance to child processes.

Learn more

Quote Parsing

Advanced parsing system handling single quotes, double quotes, and escape sequences for proper command interpretation and execution.

Learn more

Feature Highlights

These 6 key features work together to create an exceptional user experience, combining functionality with modern design principles.

Development Journey

Key milestones and phases that shaped this project from concept to completion

Phase 1

Basic Shell Structure

Implemented the fundamental shell loop with command reading, basic parsing, and simple command execution without advanced features.

Command Loop Basic Parsing Process Creation
Phase 2

Built-in Commands

Developed essential built-in commands including echo, cd, pwd, export, unset, env, and exit with proper option handling and error management.

Built-ins Error Handling Command Options
Phase 3

Advanced Parsing

Implemented advanced parsing features including quote handling, variable expansion, and complex command parsing with proper tokenization.

Quote Parsing Variable Expansion Tokenization
Phase 4

I/O & Signals

Added I/O redirection support and comprehensive signal handling for a complete shell experience with proper resource management.

I/O Redirection Signal Handling Resource Management

Code Spotlight

Command parsing and execution with I/O redirection

minishell.c
C
// Command parsing and execution structure
typedef struct s_cmd
{
    char    **args;
    char    *infile;
    char    *outfile;
    int     append;
    int     pipe_fd[2];
    struct s_cmd *next;
} t_cmd;

// Execute command with proper I/O redirection
int execute_command(t_cmd *cmd, char **envp)
{
    pid_t   pid;
    int     status;
    
    if (is_builtin(cmd->args[0]))
        return (execute_builtin(cmd));
    
    pid = fork();
    if (pid == 0)
    {
        // Child process: setup I/O redirection
        if (cmd->infile)
            setup_input_redirection(cmd->infile);
        if (cmd->outfile)
            setup_output_redirection(cmd->outfile, cmd->append);
        if (cmd->next)
            setup_pipe(cmd->pipe_fd);
            
        // Execute the command
        execve(get_command_path(cmd->args[0]), cmd->args, envp);
        perror("execve failed");
        exit(1);
    }
    else if (pid > 0)
    {
        // Parent process: wait for child
        waitpid(pid, &status, 0);
        return (WEXITSTATUS(status));
    }
    return (-1);
}

// Built-in command: change directory
int builtin_cd(char **args)
{
    char *path;
    char cwd[PATH_MAX];
    
    if (!args[1])
        path = getenv("HOME");
    else
        path = args[1];
        
    if (chdir(path) != 0)
    {
        perror("cd");
        return (1);
    }
    
    // Update PWD environment variable
    if (getcwd(cwd, sizeof(cwd)))
        setenv("PWD", cwd, 1);
        
    return (0);
}

Code Explanation

This code snippet demonstrates key functionality and implementation patterns used throughout the project.

Technical Challenges

Complex problems encountered during development and the innovative solutions that overcame them

Command Parsing Complexity

Challenge

Implementing a robust parser that handles quotes, escape sequences, variable expansion, and complex command structures accurately.

Solution

Developed a multi-stage parsing system with tokenization, quote handling, and variable expansion phases for accurate command interpretation.

Deep dive

Process Management

Challenge

Managing child processes, handling process communication, and ensuring proper cleanup of resources and zombie processes.

Solution

Implemented proper fork/exec patterns with waitpid for process management and signal handling for clean process termination.

Deep dive

I/O Redirection

Challenge

Implementing complex I/O redirection with pipes, file redirection, and maintaining proper file descriptor management.

Solution

Created a systematic approach to I/O redirection using dup2 system calls and proper file descriptor management with error handling.

Deep dive

Ready to Explore?

Experience the project firsthand or dive into the source code to see how it all comes together. Your feedback and contributions are always welcome!

Star on GitHub
Share Project
Give Feedback