/minishell

A small shell entirely in C (no LEX/FLEX/YACC/BISON)

Primary LanguageC

Introduction

Minishell is a project from the cursus of the school 42 (campus of Le Havre).

The goal of this project is to make a rather simple shell. See the list of features down below.


Dependencies

List

Microparser

microparser, a home made LR / LALR / SLR parser made by ale-boud.

Libft

libft, the full libft (highly documented) made by amassias.

Readline

readline, command line edition, history support (GNU)


Minishell

Build

Commands to build minishell :

git clone --recurse-submodules https://github.com/Lailouezzz/minishell
cd minishell
./configure.sh && make

Features

  • Prompt when waiting for a new command
  • Working history
  • Search and launch the right executable (based on the PATH variable or using a relative or an absolute path).
  • Not interpret unclosed quotes or special characters which are not required by the subject such as \ (backslash) or ; (semicolon)
  • (single quote) should prevent the shell from interpreting the meta- characters in the quoted sequence
  • " (double quote) should prevent the shell from interpreting the meta- characters in the quoted sequence except for $ (dollar sign)
  • Redirections
    • < redirects input
    • > redirects output
    • << [DELIMITER] reads the input until a line containing the delimiter is seen. However, it doesn’t have to update the history
    • >> redirects output in append mode
  • Pipes (| character). The output of each command in the pipeline is connected to the input of the next command via a pipe
  • Environment variables ($ followed by a sequence of characters) which should expand to their values
  • $? which should expand to the exit status of the most recently executed foreground pipeline
  • Ctrl-C, Ctrl-D and Ctrl-\ which should behave like in bash
  • Interactive mode
    • Ctrl-C displays a new prompt on a new line
    • Ctrl-D exits the shell
    • Ctrl-\ does nothing
  • Builtins
    • echo with option -n
    • cd with only a relative or absolute path
    • pwd with no options
    • export with no options
    • unset with no options
    • env with no options or arguments
    • exit with no option
  • Command chaining (&& and ||)
  • Subshell with (COMMAND)
  • Wildcard (* character) for the current working directory

Automaton

This project is powered by a DFA (deterministic finite automaton) LALR(1) made from a simplified bash grammar.

Grammar

command_line ::= and_or

and_or ::= pipeline | and_or AND_OR pipeline

pipeline ::= command | pipeline '|' command

command ::= simple_command | subshell redirect_list | subshell

subshell ::= '(' and_or ')'

simple_command ::= redirect_list pn args_red_list
				| pn args_red_list
				| redirect_list pn
				| pn

redirect_list ::= io_info | redirect_list io_info

io_info ::= IO WORD

pn ::= WORD

args_red_list ::= args_red | args_red_list args_red

args_red ::= WORD | io_info

Automaton representation

Error

Todo

  • Doxygen documentation

Authors

ale-boud amassias