Skip to content

About

A brief and simple recreation of the Bash shell

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

277 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

This project has been developed as part of the 42 curriculum by atabarea and medel-ca.

Minishell

Minishell is a minimal command-line shell written in C. It supports basic functionalities like command execution, pipes, redirections, and environment variable handling, similar to a simplified version of Bash.


Table of Contents

  1. Description
  2. Instructions
  3. Resources

Description

Minishell is designed to demonstrate low-level system programming concepts in C, including:

  • Executing system commands.
  • Input/output redirections (>, >>, <).
  • Command pipelines (|).
  • Expanding environment variables ($HOME, $PATH, etc.).
  • Basic built-in commands: cd, echo, exit, export, unset.
  • Syntax error handling.

It serves as a learning exercise for processes, pipes, memory management, and command parsing in C.


Instructions

  1. Clone the repository

  2. Go into the minishell folder

cd minishell
  1. Compile the program using Make
make
  1. Run the program:
./minishell
  1. A prompt will appear. You may enter your commands to be executed. Our minishell supports:
  • Prompt display
  • Command history (up and down arrows)
  • System executables available from the environment (ls, cat, grep, etc)
  • Local executables (./minishell)
  • Builtin commands:
    • echo (and option -n)
    • cd (with only a relative or absolute path)
    • pwd (no options)
    • export (no options)
    • unset (no options)
    • env (no options or arguments)
    • exit (with exit number but no other options)
  • Pipes | which redirect output from one command to input for the next
  • Redirections:
    • '>' redirects output
    • '>>' redirects output in append mode
    • < redirects input
    • << DELIMITER displays a new prompt, reads user input until reaching DELIMITER, redirects user input to command input (does not update history)
  • Environment variables (i.e. $USER or $VAR) that expand to their values.
  • $? expands to the exit status of the most recently executed foreground pipeline.
  • $$ expands to the process ID.
  • User keyboard signals:
    • ctrl-c: When used in the father process displays a new prompt line. When used during the execution of a command ends the command (try with sleep 10)
    • ctrl-d When used in the father process exits the shell. When used during the execution of a command is ignored (try with sleep 10)
    • ctrl-\ does nothing However, Minishell does not support , ;, &&, ||, or wildcards.

Resources

First aproximations to the project: Minishell: Building a mini-bash MINISHELL 42: parsing Minishell explained The bash guide

Lexer and Parser of the input: Arbol de sintaxis abstracta Context free grammar Shell command lexer Lexical analyzer in C

Executing child processes and redirections: Pipe() system call

Other useful links: Explain shell

About

A brief and simple recreation of the Bash shell

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages