Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

426 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by ydylan-k, sming-zh.

Minishell

As beautiful as a shell

Description

Minishell is a 42 project aimed at creating a minimal yet fully functional shell based on Bash. The primary goal of this project is to understand core system architecture by building it from scratch, specifically focusing on Lexical Analysis, Process Management, Inter-Process Communication (IPC), Environment Management, Signal Handling.

Key Features Implemented

  • libreadline-dev is used to await and read for user input. It's prefixed with :3.
  • Mandatory Built-ins:
    • echo: Prints text into standard output followed by a line break. Prepend with -n flag to disable line break.
       :3 echo hello
       hello
       :3 echo -n hello
       hello:3 echo hello
       hello
       :3
    • cd: Changes current working directory to another
    • pwd: Shows current working directory
    • export: Shows or creates an environment variable with format <key>=<value>
       :3 export six=seven
       :3 echo $six
       seven
       :3 export
       declare -x six="seven"
       :3
    • unset: Deletes an environment variable
    • env: Shows all shell variables
    • exit: Exits current shell with optional exit code
  • Quote Interpretation:
  • ' (Single Quotes): Prevents the shell from interpreting meta-characters (literal string).
  • " (Double Quotes): Prevents the shell from interpreting meta-characters, except for $ (allows variable expansion).
  • Redirections:
    • <: Redirects terminal input from a specified file.
    • >: Redirects terminal output to a specified file (truncates).
    • << (Heredoc): Reads multi-line input from the terminal until a specified delimiter is seen.
    • >>: Redirects terminal output to a specified file in append mode.
  • Pipelines (|): Connects the output of one command directly into the input of the next using precise file descriptor management.
  • Environment Variables: Expands variables (e.g., $USER) and handles $?, which dynamically expands to the exit status of the most recently executed foreground pipeline.
  • Signal Handling: Custom behavior for Ctrl+C (SIGINT), Ctrl+\ (SIGQUIT), and Ctrl+D (EOF) depending on whether the shell is in an interactive prompt, reading a heredoc, or executing a blocking command.
  • Wildcard Expansion (*): Scans your directory to replace * patterns with real filenames. It ignores hidden files, won't expand if inside quotes, and keeps the pattern if no files match.

Instructions

Compilation

Minishell requires libreadline-dev which can be downloaded from your operating system's package manager.

  • Run make all to compile the program.
  • make clean to remove the object files.
  • make fclean to remove both the binary and the object files.
  • make re to make fclean and make all again.

Usage

./minishell
:3 echo hello
hello
:3 ls -a
.  ..  minishell
:3 exit
exit

Resources

Lexer

Parser

Heredoc

Environment Variable

Execution

Signal

Wildcard

Others

The usage of AI in this project was used for all parts of this project. Like brainstorming and understanding data structure, execution pipeline, pipes, redirection, file descriptor handling, refactoring code, documentations, wildcard solving, and writing documentations.

rentry version

About

A minimal linux shell based on Bash.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages