Skip to content

LilianMS/MiniShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


🇺🇸 | 🇧🇷

🐚 Minishell

approved-+-bonus-101% made-with-c

Minishell is a project developed at 42 São Paulo with the goal of recreating a minimalist shell, capable of interpreting and executing commands in a terminal — just like Bash.

This is one of the most challenging and fundamental projects in the 42 core curriculum, requiring a deep understanding of process management, memory handling, data structures, and command interpretation.

Built in collaboration: @Letícia Sampietro and @Lilian Mendes.


🚀 Project Goals

  • Implement a fully functional shell that supports:
    • Execution of system and built-in commands (e.g., ls, echo, cat, etc.);
    • Pipes (|) and redirections (<, >, >>, <<);
    • Proper handling of exit codes and error management;
  • Handle a wide variety of user inputs, including invalid and edge cases;
  • Build built-in commands (cd, exit, env, export, etc.) to be executed by the program;

🧠 Key Concepts Implemented

1. Initial Validation

  • Basic error handling and input validation before processing the command line.

2. Tokenization

  • Input is broken into tokens using a finite state machine.
  • Each token is stored as a node in a doubly linked list, representing commands, arguments, or operators (pipes, redirects...).

3. Parsing

  • Semantic analysis of the token list, including:
    • Handling of single and double quotes
    • Commands + Arguments grouping
    • Processing of pipes and redirects, including heredoc

4. Abstract Syntax Tree (AST)

  • Tokens are organized into a binary tree, where:
    • Each node represents a command or an operator (pipe or redirect) and bifurcates into other two (when possible)
    • If there is a pipe, it will always be the first node, followed by any other operators
    • Commands will always be on the left side branch of operators
    • Execution begins recursively from the leftmost node

5. Execution

  • Recursive traversal of the AST:
    • Each node is evaluated as a simple command, pipe, redirection, or builtin
    • Uses fork(), execve(), and pipe() to manage processes
    • Ensures correct return codes and cleanup after execution

📂 How to Run

Clone the repository:

bash
git clone https://github.com/LilianMS/MiniShell.git
cd minishell
make

🇺🇸 | 🇧🇷

🐚 Minishell em português

Minishell é um projeto desenvolvido na 42 São Paulo com o objetivo de recriar um shell minimalista, capaz de interpretar e executar comandos no terminal — assim como o Bash.

Esse é um dos projetos mais desafiadores e fundamentais do currículo da 42, exigindo profundo entendimento de gerenciamento de processos, manipulação de memória, estruturas de dados e interpretação de comandos.

Desenvolvido em colaboração: @Letícia Sampietro e @Lilian Mendes.


🚀 Objetivos do Projeto

  • Implementar um shell totalmente funcional com suporte a:
    • Execução de comandos do sistema e comandos internos (como ls, echo, cat, etc.);
    • Pipes (|) e redirecionamentos (<, >, >>, <<);
    • Tratamento correto de códigos de saída e gerenciamento de erros;
  • Tratar uma ampla variedade de entradas do usuário, incluindo casos inválidos e extremos;
  • Construir comandos internos (cd, exit, env, export, etc.) executados diretamente pelo programa;

🧠 Conceitos-Chave Implementados

1. Validação Inicial

  • Tratamento básico de erros e validação de entrada antes do processamento da linha de comando.

2. Tokenização

  • A entrada é dividida em tokens usando uma máquina de estados finita.
  • Cada token é armazenado como um nó em uma lista duplamente encadeada, representando comandos, argumentos ou operadores (pipes, redirecionamentos...).

3. Análise Sintática

  • Análise semântica da lista de tokens, incluindo:
    • Tratamento de aspas simples e duplas
    • Agrupamento de comandos + argumentos
    • Processamento de pipes e redirecionamentos, incluindo heredoc

4. Árvore de Sintaxe Abstrata (AST)

  • Os tokens são organizados em uma árvore binária, onde:
    • Cada nó representa um comando ou um operador (pipe ou redirecionamento) e se bifurca em outros dois (quando possível)
    • Se houver um pipe, ele será sempre o primeiro nó, seguido por quaisquer outros operadores
    • Os comandos estarão sempre no ramo esquerdo dos operadores
    • A execução começa recursivamente a partir do nó mais à esquerda

5. Execução

  • Percurso recursivo da AST:
    • Cada nó é avaliado como um comando simples, pipe, redirecionamento ou builtin
    • Utiliza fork(), execve() e pipe() para gerenciar processos
    • Garante códigos de retorno corretos e limpeza de recursos após a execução

📂 Como executar

Clonar o repositório:

bash
git clone https://github.com/LilianMS/MiniShell.git
cd minishell
make

About

Projeto da 42 - Minishell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •