Giter Club home page Giter Club logo

minishell's Introduction

About

Minishell is a UNIX-like shell implemented in C, aiming to provide a basic replica of a bash-like shell. It supports a variety of features including command execution, I/O redirection, pipelines, variable expansion, command history, tab completion, signal handling, and exit status handling. Find a detailed list of requirements for this project here: subject.pdf.

Usage

git clone this project cd into it and make. the program is executed as so:

./minishell

The program will then prompt you for input. It is used exactly as a bash shell as such:

ls -l
echo "Hello world"
cat file.txt

Key features

  • Command execution
  • I/O redirection
  • Pipelines
  • Variable expension
  • Command history
  • Tab completion
  • Signal handling
  • exit status handling

Implementation

The program uses the readline library to prompt input to the user and can be divided into four main parts.

  1. Lexer (Tokenizer):
  • The lexer tokenizes the input command line string into individual tokens using get_token() function.
  • It skips over leading spaces and identifies various types of tokens, including commands, arguments, and redirection operators.
  • Special characters like quotes are handled to ensure correct tokenization.
  1. Expander:
  • The expander is responsible for expanding variables in the command line.
  • It identifies variables prefixed with $ and replaces them with their corresponding values.
  • Special variables like $? for exit status are supported.
  1. AST (Abstract Syntax Tree) Generator:
  • The AST generator constructs a tree structure representing the syntax of the command line input.
  • It parses commands, arguments, and redirections and organizes them into a hierarchical tree.
  • Commands separated by pipes (|) are connected as nodes in the tree.
  1. Executor:
  • The executor executes the commands represented by the AST.
  • It matches commands with built-in functions or external executables and executes them accordingly.
  • I/O redirection, command execution in child processes, and handling of exit statuses are managed within the executor.

Testing

cd into the test/ directory and run ./tester. The tester was developed by Lucas Kuhn (minishell tester) and was really usefull to rigouresly test for errors. Tests can be added in the "test/extras" file to cover more aspects of the shell.

Norme

All 42 projects must be written following the Norme.

- No for, do while, switch, case or goto are allowed
- No more than 25 lines per function and 5 functions per file
- No assigns and declarations in the same line (unless static)
- Each line must be at most 80 columns wide, comments included
- A function can take 4 named parameters maximum
- No more than 5 variables in 1 function

minishell's People

Contributors

umtalj0ta avatar axel-ex avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

umtalj0ta

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.