Skip to content

Aymanesaj/minishell

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”₯ Minishell πŸ”₯

Minishell is a minimalistic Unix shell implemented in C, replicating core behaviors of Bash with a focus on learning system calls, process handling, and parsing logic. Built as part of the 42 curriculum, this project introduces you to building your own command-line shell with custom parsing, environment management, and execution logic.


πŸ› οΈ Features

βœ… Supported:

  • Execution of binaries from PATH and with absolute/relative paths

  • Built-in commands:

    • echo, cd, pwd, export, unset, env, exit
  • Redirections:

    • >, >>, <, << (heredoc with correct handling of quotes and signals)
  • Pipes: cmd1 | cmd2 | cmd3

  • Environment variables: $VAR, including proper expansion

  • Quote handling:

    • Single quotes ' prevent expansion
    • Double quotes " allow expansion
  • Signal handling (Ctrl+C, Ctrl+D) with prompt restoration

  • Exit status propagation

  • Wildcard (*) expansion for current directory

  • Logical operators (Bonus):

    • &&, || for conditional execution
  • Parentheses ( ) (Bonus) for grouped commands and prioritization


πŸ“š Project Structure

1. Lexer

The first step splits the user input into tokens while respecting shell grammar (quotes, operators, etc.).

2. Parser

The lexer output is parsed into an Abstract Syntax Tree (AST) representing command execution flow.

3. Execution

The AST is traversed to execute commands:

  • Pipes are forked and connected via dup2
  • Redirections are opened and applied before command execution
  • Built-ins are executed in the parent or child depending on context
  • Logical operators (&&, ||) are handled via AST nodes

4. Heredoc Handling

Heredocs are processed in a forked child and stored in temporary files. They respect quotes and stop on correct delimiters or on signal SIGINT.

5. Wildcard Expansion

When encountering *, minishell expands it to match filenames in the current directory using opendir() and readdir().


πŸ§ͺ Bonus Features

  • βœ… Logical operators: &&, ||
  • βœ… Parenthesis grouping: (...)
  • βœ… Wildcard expansion: *

πŸ§‘β€πŸ’» Usage

make
./minishell

Type commands just like in bash:

πŸ€– minishell echo Hello $USER
Hello othmane

πŸ€– minishell ls -l | grep minishell
-rwxr-xr-x  1 othmane  staff  134528 May  6 15:42 minishell

πŸ€– minishell cat << EOF
Hello minishell
EOF
Hello minishell

πŸ€– minishell mkdir test && cd test || echo fail

πŸ€– minishell (echo one && echo two) || echo three
one
two

πŸ€– minishell echo *
file1.txt file2.c minishell README.md

πŸ’€ minishell ls no_such_file
ls: cannot access 'no_such_file': No such file or directory

⚠️ Signals

  • Ctrl+C interrupts the current input or heredoc and restores the prompt
  • Ctrl+D exits the shell or ends input when appropriate

πŸ‘¨β€πŸ‘©β€πŸ‘§ Authors

This project was developed collaboratively by a team of students at [1337 School / 42 Network].

@bg-otman

@Aymanesaj

About

🐚 Minishell: As Beautiful as a Shell can be A minimalist implementation of a Bash-like shell, created to explore the depths of processes, file descriptors, and system calls. This project is a deep dive into the inner workings of how an Operating System executes commands.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C 98.3%
  • Makefile 1.7%