/MiniShell

Minishell is a project developed as part of the curriculum at 42 School. It aims to deepen understanding of process management and shell functionality.

Primary LanguageCMIT LicenseMIT

Minishell

As beautiful as a shell

Overview

Minishell is a project designed to create a simple, custom shell in C, closely mimicking the functionality of Bash. The project focuses on understanding processes, file descriptors, and various shell operations. This README provides a detailed guide on the structure, functionality, and usage of the Minishell project.

Table of Contents

  1. Introduction
  2. Features
  3. Installation
  4. Usage
  5. Built-in Commands
  6. Acknowledgments

Introduction

The existence of shells is linked to the very existence of IT. Initially, developers used aligned 1/0 switches to communicate with computers, which was quite cumbersome. The invention of shells allowed interactive command-line communication in a language closer to human language. With Minishell, we revisit the fundamental problems faced before modern GUIs and sophisticated shells like Bash.

Features

Minishell includes the following features:

  • Display a prompt while waiting for a new command.
  • Maintain a working history of commands.
  • Search and execute the correct executable based on the PATH variable or using a relative/absolute path.
  • Handle single and double quotes to manage metacharacters.
  • Implement input (<), output (>), append (>>), and here-document (<<) redirections.
  • Support pipes (|) to connect the output of one command to the input of another.
  • Manage environment variables and special parameter $? for the exit status of the most recently executed foreground pipeline.
  • Handle ctrl-C, ctrl-D, and ctrl-\ signals as in Bash.
  • Built-in commands: echo, cd, pwd, export, unset, env, and exit.

Installation

To install and run Minishell, follow these steps:

  1. Clone the Repository

    git clone <repository-url>
    cd minishell
  2. Build the Project

    make
  3. Run Minishell

    ./minishell

Usage

Once Minishell is running, you can use it similarly to Bash:

  • Basic Commands

    ls -l
    echo "Hello, World!"
  • Redirections

    cat < input.txt
    echo "New content" > output.txt
    echo "Append this" >> output.txt
    cat << EOF
    > This is a
    > here-document example
    > EOF
  • Pipes

    ls -l | grep minishell
  • Environment Variables

    echo $HOME
    echo $?
  • Signal Handling

    • ctrl-C: Displays a new prompt on a new line.
    • ctrl-D: Exits the shell.
    • ctrl-\: Does nothing.

Built-in Commands

Minishell implements several built-in commands:

  • echo

    echo -n "No newline"
  • cd

    cd /path/to/directory
  • pwd

    pwd
  • export

    export VAR=value
  • unset

    unset VAR
  • env

    env
  • exit

    exit