Code Monkey home page Code Monkey logo

minishell's Introduction

Minishell | 42Paris | As beautiful as a shell ๐Ÿš

Minishell is a project that involves creating your very own shell, taking inspiration from the Bash reference, from ground up with no pre-existing library, including key functionalities such as command execution, input/output redirection, and process management.

Introduction

A shell, in the context of operating systems, is like a command interpreter that communicates with the operating system kernel. It allows users to execute commands, create or delete files and directories, read and write file contents, and perform various other tasks from a command line interface.

Limitations

  • No built-in library is allowed in this project. all functions must be written from scratch.
  • Only one global variable is allowed.

Our Implementation of Minishell

The table displays the commands and the extensions were in scope of this project:

Builtin Description Options Parameters Helpful Functions
echo Prints arguments separated with a space followed by a new line -n โœ”๏ธ write
cd Changes current working directory, updating PWD and OLDPWD โŒ โœ”๏ธ chdir
pwd Prints current working directory โŒ โŒ getcwd
env Prints environment โŒ โŒ write
export Adds/replaces variable in environment โŒ โœ”๏ธ โŒ
unset Removes variable from environment โŒ โœ”๏ธ โŒ

Our Minishell implementation involves several key components:

Lexer and Expander

  • The lexer and expander handle tasks like expanding environment variables (e.g., $USER), expanding '~' to the user's home directory, and tokenizing the input string.
  • We split the input string into tokens, taking spaces and quotes into account, and then apply expansion functions to each substring.
  • For example, the string: echo "hello there" how are 'you 'doing? $USER |wc -l >outfile is split into: {echo, "hello there", how, are, 'you 'doing?, $USER, |wc, -l, >outfile, NULL}. After expansion, it becomes: {echo, "hello there", how, are, 'you 'doing?, pixel, |wc, -l, >outfile, NULL}

Parser

  • The parser stores the tokenized and expanded string in a linked list of commands.
  • It creates a chain list data structure that holds information about each command, including the command name, parameters, full path to the executable, input and output file descriptors, environment variables, and process ID:
  • Screen Shot 2023-09-01 at 2 10 18 PM

Executor

  • The executor uses the data provided by the parser to execute commands.
  • It handles both built-in commands and external commands by creating child processes with proper input and output redirection.
  • After all commands have executed, the exit status of the most recently executed command is retrieved.

Installation

Prerequisites

This project was designed and tested on Linux, if used by mac updates may be needed. Ensure you have the following packages installed:

  • gcc
  • make
  • python-norminette
  • readline

Usage

The project compiles an executable called minishell saved inside a bin/ folder), and it is compiled using the .c files inside the src/ folder. once you run the executable ./minishell a new prompt is opened where you can execute commands and see results.

Basic Demo

This is a basic demo, go ahead and explore more!! HAVE FUN!!

Screen.Recording.2023-09-22.at.12.36.04.PM.mov

References

minishell's People

Contributors

kitchener-leslie avatar shimazadeh avatar

Watchers

 avatar

Forkers

diclesonmez

minishell's Issues

pipex issue

outfile1 | outfile1

doesnt work properly!

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.