Skip to content

md-dev970/minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

154 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minishell

Minimal bash-like shell written in C.

Overview

This project involves writing a simple shell in C with basic functionalities. The project can be divided into 6 key parts:

Lexing

Divide the input commands into lexical units called "tokens" and assign a type for each token.

Parsing

Analyse the tokens and check if the input command conforms with the defined grammar.

Preparing for execution

This step includes opening files, redirecting input/output, processing heredocs, expanding environement variables, and removing quotes

Executing non built-ins

Search for the binary in the directories of the PATH variables, or if a path is provided check if the executable can be accessed

Executing built-ins

Implement the following built-ins: cd, pwd, echo, export, unset, exit

Signal handling

Handle interruption signals just like bash does : ◦ ctrl-C displays a new prompt on a new line. ◦ ctrl-D exits the shell. ◦ ctrl-\ does nothing (instead of the default behaviour of quitting and generating a core dump).

Key features

Key features include:

  • A working history.
  • Searching and launching the right executable (based on the PATH variable or using a relative or an absolute path).
  • Handling single (') and double (") quotes.
  • Input/output redirections:
    • < redirects input.
    • > redirects output in truncate (overwrite) mode.
    • << [delimiter] : reads the input until a line containing the delimiter is seen.
    • >> redirects output in append mode.
  • Handling pipes (| character). The output of each command in the pipeline is connected to the input of the next command via a pipe.
  • Expanding environment variables (i.e echo $var prints the values stored in the variable var)

How to run

Dependencies

Minishell requires the readline library in order to function. You can install it using your favorite package manager.

Build

To build the debug version of the minishell, cd into the project's root directory and run:

make

For the release version, run:

make release

To clean build files, run:

make clean

About

A minimal bash-like shell written in C.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors