Skip to content

vde-maga/42-minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

143 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42 - Minishell

Language 42 Porto Status

About

Minishell is a project developed as part of the 42 school curriculum. It is an implementation of a Unix shell in the C language that offers basic command interpreter functionality, including parsing, command execution, redirection, pipes, and environment variable manipulation.

In this project, I had to work with advanced concepts such as memory management, processes, signals, and complex data structures such as abstract syntax trees (AST).

Evaluation

Evaluation Screenshot

Features

Main Features

  • Lexer: Tokenization of user input
  • Parser: Abstract syntax tree (AST) construction
  • Executor: Command execution with support for pipes and redirections
  • Builtins: Implemented internal commands (echo, cd, pwd, export, unset, env, exit)
  • Expander: Expansion of environment variables and wildcards
  • Heredoc: Support for heredoc with conditional variable expansion
  • Signals: Proper handling of signals (SIGINT, SIGQUIT)
  • History: Command history with readline

Technical Features

  • Process Management: Fork, exec, wait
  • Redirections: <, >, >>, <<
  • Pipes: Communication between processes
  • Logical Operators: &&, || with short-circuiting
  • Subshells: Execution in subprocesses with parentheses
  • Environment Variables: Complete environment manipulation
  • Wildcards: Pattern expansion with *

Installation and Compile

Dependencies

  • GCC Compiler
  • Readline Library
  • Make
  • Libft Library (already included)

Compiling

# Compile
make

# Clean Object Files
make clean

# Clean All
make fclean

# Recompile
make re

# Debugging
make valgrind

Instructions

Use

./minishell

Commands Examples

# Basic Command
ls -la
echo "Hello World"
pwd

# Redirects
echo "test" > file.txt
cat < file.txt

# Pipes
ls -la | grep ".c"

# Heredoc
cat << EOF
Hello
World
EOF

# Logic Operators
echo "success" && echo "also success"
echo "fail" || echo "this will print"

# Environment Variables
export MY_VAR="value"
echo $MY_VAR
unset MY_VAR

# Subshells
(cd /tmp && ls)

Builtins

Command Description Features
echo Displays arguments Supports -n flag, multiple arguments
cd Changes directory Supports ~, -, --, updates PWD/OLDPWD
pwd Displays current directory Absolute path
export Sets/exports variables Creates/updates environment variables
unset Removes variables Removes variables from the environment
env Displays environment Lists all environment variables
exit Exits shell Optional exit code, resource cleanup

Execution Flow

graph TD
    A[User Input] --> B[Lexer]
    B --> C[Tokens]
    C --> D[Parser]
    D --> E[Syntactic Validation]
    E --> F[AST Construction]
    F --> G[Expander]
    G --> H[Variable Expansion]
    H --> I[Wildcard Expansion]
    I --> J[Executor]
    J --> K[Bultins?]

    K -- Yes --> L[Execute Directly]
    K -- No --> M[Fork + Exec]

    L --> N[Update State]
    M --> N

    N --> O[Next Command]
Loading

About

This project is about creating a simple shell. Yes, your very own little Bash. You will gain extensive knowledge about processes and file descriptors.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors