tiziaco / minishell

Replicate the Linux shell.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

minishell

This repository contains a minimalistic shell interpreter, a project completed for School 42. The minishell implements basic functionalities expected from a command-line shell.

Features

  • Advanced string handling: Handles escaping of backslashes () and preserves quoted arguments (single and double quotes).
  • Redirection: Supports input (<), output (>), and here-string (<<) redirection with delimiter. Supports appending output (>>).
  • Piping: Connects multiple commands via pipes (|) for chained execution.
  • Environment variables: Expands environment variables denoted by $.
  • Exit status: $? expands to the exit status of the last foreground pipeline.
  • Signal handling: Responds to ctrl-C (display new prompt), ctrl-D (exit), and ctrl-\ (no action) like Bash.

Built-in commands:

  • echo with option -n to suppress newline.
  • cd with relative or absolute path.
  • pwd to print working directory.
  • export to add environment variables.
  • unset to remove environment variables.
  • env to list environment variables.
  • exit to terminate the minishell.

Architecture

A Linux shell interpreter follows a general monolithic architecture for understanding user commands and getting things done. Here's a simplified breakdown of the different components:

  1. Input: The shell can take input from two places: the keyboard (interactive mode) or a file (batch mode).
  2. Parsing: The shell reads the input line by line and breaks it down into individual commands, arguments, and options.
  3. Execution: For each command, the shell:
    • Locates the program or built-in function associated with the command.
    • Creates a new child process (using fork).
    • Replaces the child process with the program (using exec). This essentially lets the program take over the child process.
  4. I/O Redirection: The shell can redirect the standard input (stdin) and output (stdout) of a command to/from files.
  5. Waiting: The parent shell might wait for the child process to finish (using wait).

This basic structure allows the shell to understand what the user wants, run the appropriate programs, and manage their execution.

Getting Started

  1. Clone the repository:
git clone --recurse-submodules https://github.com/tiziaco/minishell.git
  1. Compile the code:
make
  1. Run the minishell:
./minishell

Usage

The minishell accepts user commands in the following format:

<command> [arguments]

About

Replicate the Linux shell.


Languages

Language:C 97.7%Language:Makefile 2.3%