Giter VIP home page Giter VIP logo

hheghine / minishell Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 5.7 MB

As beautiful as a shell․.. Minishell is a lightweight implementation of POSIX shell designed to provide a minimalistic command-line interface for interacting with an operating system.

Makefile 1.01% C 63.20% M4 0.46% Roff 6.68% Shell 6.22% Perl 6.26% TeX 16.01% C++ 0.15%
42born2code 42cursus 42projects 42school bash c posix shell

minishell's Introduction

Minishell

A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.

This project is about creating a simple shell.

Screenshot from 2023-11-07 23-34-49

What Is Bash and How Does It Work?

The shell is a program that that takes keyboard commands and passes them to the operating system to carry out. Almost all Linux distributions supply a shell program from the GNU Project called Bash. The name is an acronym for "Bourne-again shell," in reference to the fact that Bash is an enhanced replacement for "sh," the original Unix shell program written by Steve Bourne.

So how bash actually works? Essentially it breaks down the process into 4 steps: lexerparserexpanderexecutor.

The general idea for this shell is reading a string of commands in a prompt using readline.

The Challenge

  • Follow the shell syntax.
  • Not use more than one global variable.
  • Display a promt while waiting for a new commmand.
  • Have a working history.
  • Find and launch executables (using the PATH variable or an absolute path).
  • Handle ' (single quote) which should prevent the shell from interpreting the metacharacters in the quoted sequence.
  • Handle " (double quote) which should prevent the shell from interpreting the metacharacters in the quoted sequence except for $ (dollar sign).
  • Implement redirections such as:
    • < redirect input.
    • > redirect output.
    • << heredoc (doesn't affect history).
    • >> redirect output in append mode.
  • Implement | (pipes).
  • Handle environment variables.
  • Handle $?.
  • ctrl-C, ctrl-D, and ctrl-\ should behave like in bash.
  • Recreate the following builtins:
    • echo with option -n.
    • cd with only a relative or absolute path.
    • pwd (no flags).
    • export (no flags).
    • unset (no flags).
    • env (no flags or arguments).
    • exit (no flags).

Visuals

ANSI Escape Sequences: Colours

#!/bin/bash
#
#   This file echoes a bunch of color codes to the 
#   terminal to demonstrate what's available.  Each 
#   line is the color code of one forground color,
#   out of 17 (default + 16 escapes), followed by a 
#   test use of that color on all nine background 
#   colors (default + 8 escapes).
#

T='gYw'   # The test text

echo -e "\n                 40m     41m     42m     43m\
     44m     45m     46m     47m";

for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
           '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
           '  36m' '1;36m' '  37m' '1;37m';
  do FG=${FGs// /}
  echo -en " $FGs \033[$FG  $T  "
  for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
    do echo -en "$EINS \033[$FG\033[$BG  $T  \033[0m";
  done
  echo;
done
echo

minishell's People

Contributors

hheghine avatar tigranmn avatar

Watchers

 avatar

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.