Skip to content

Kobayashi82/Minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

System & Kernel Shell Protocol Command C Language

A basic Bash-style shell implementation

Minishell

README en EspaΓ±ol

Minishell is a 42 School project that implements the basic features of a shell like Bash.
This version includes all mandatory requirements, the bonus, and some additional features.

✨ Features

Core Functionality

  • Interactive command line: Clean prompt with command history
  • Command execution: PATH resolution, absolute/relative execution
  • Process management: Fork/exec model with proper signal handling
  • Environment variables: Full support for variable expansion and manipulation
  • I/O redirection: Input/output redirection with append mode
  • Pipes: Command chaining with pipe operators
  • Heredoc: Advanced input redirection mechanisms
  • Syntax checking: Detection and reporting of syntax errors

Advanced Features

Improved parsing

  • Command substitution: $() for command substitution
  • Non-interactive mode: -c option to run commands directly
  • Herestring: <<< for direct string input
  • Heredoc expansion: Variables and commands inside heredoc and herestring
  • Quote handling: Advanced single and double quote processing
  • Character escaping: Support for \ (backslash)
  • Unclosed tokens: Displays PS2 for line continuation

Variables and expansion

  • Shell variables: Local variables in addition to environment variables
  • Special variables:
    • $$ - Shell PID
    • $RANDOM - Random number
    • $TIME - Current timestamp
    • $_ - Last argument of the previous command
    • $? - Last exit code
  • Tilde expansion: ~ expands to the home directory
  • Wildcard expansion: *, ?, and [a-z] with advanced patterns

Logical operators and control

  • Logical operators: && and || with parenthesis support for precedence
  • Subshells: () for execution in subprocesses
  • Concurrent execution: Handling of multiple processes

Builtin commands

All builtins include --help and --version:

  • echo - With -n and -e options
  • cd - With cd - support (previous directory)
  • pwd - Current directory
  • export - Environment variable management
  • unset - Remove variables
  • env - With -s to show shell variables
  • exit - Exit the shell
  • history - Command history management
  • help - Built-in help system
  • banner - Welcome message

πŸ”§ Installation

git clone git@github.com:Kobayashi82/Minishell.git
cd minishell
make

πŸ–₯️ Usage

Interactive mode

# Start minishell
./minishell

# Basic example
minishell$ echo "Hello World"
Hello World

Non-interactive mode (-c option)

# Run commands directly
./minishell -c "echo 'Hello from the command line'"
./minishell -c "ls -la | grep '.c' | wc -l"
./minishell -c "export VAR=value && echo \$VAR"

# Complex commands with pipes and redirection
./minishell -c "cat /etc/passwd | grep root > users.txt"

Usage examples

# Pipe usage
minishell$ ls -la | grep ".c" | wc -l

# Redirection
minishell$ echo "content" > file.txt
minishell$ cat < file.txt

# Variables
minishell$ export VAR="value"
minishell$ echo $VAR

# Heredoc
minishell$ cat << EOF
> line 1
> line 2
> EOF

πŸ“š Advanced examples

Command substitution

minishell$ echo "Current date: $(date)"
Current date: Mon 26 May 2025 10:30:15 CEST

minishell$ files=$(ls *.c)
minishell$ echo $files

Logical operators

minishell$ make && echo "Build succeeded" || echo "Build failed"

minishell$ (cd /tmp && pwd) && pwd
/tmp
/original/path

Wildcards

minishell$ ls *.c           # .c files
minishell$ ls file?.txt     # file1.txt, file2.txt, etc.
minishell$ ls [a-z]*.c      # .c files starting with lowercase

Herestring

minishell$ cat <<< "This is a line of text"
This is a line of text

minishell$ bc <<< "2+2"
4

πŸ§ͺ Technical Highlights

Memory management

  • βœ… No memory leaks: Full heap cleanup
  • βœ… No open file descriptors: Properly closes all FDs
  • βœ… Signal handling: Robust handling of SIGINT, SIGQUIT, EOF

Bash compatibility

  • βœ… Identical error handling: Error codes and messages like Bash
  • βœ… Signal behavior: Ctrl-C, Ctrl-D, Ctrl-\ like Bash
  • βœ… Special variables: Identical behavior to Bash

Robust parsing

  • βœ… Recursive parser: Complete syntax parsing
  • βœ… Error handling: Detailed error detection and reporting
  • βœ… Advanced tokenization: Support for complex tokens

πŸ“„ License

This project is licensed under the WTFPL – Do What the Fuck You Want to Public License.


🐚 Developed as part of the 42 School curriculum 🐚

"In Minishell, the last feature is never really the last"

About

Minimalist Unix-like shell in C

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors