Skip to content
C1STAPublic

About

A Bash-inspired shell in C with parsing, pipelines, redirections, expansion, builtins, and signal handling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

Minishell

Build

A Bash-inspired command-line interpreter written in C. Minishell reads and parses interactive commands, expands environment variables, builds execution structures, and coordinates processes, pipes, redirections, and signals.

Developed as a two-person project at 42 Paris, it focuses on the Unix mechanisms behind a shell rather than reproducing every Bash feature.

Features

  • Interactive prompt and command history powered by GNU Readline
  • Executable lookup through PATH and direct relative or absolute paths
  • Single and double quotes with environment-variable expansion
  • Pipelines connecting any number of commands
  • Input, output, append, and heredoc redirections: <, >, >>, and <<
  • Exit-status expansion through $?
  • Interactive handling of Ctrl-C, Ctrl-D, and Ctrl-\
  • Builtins: echo, cd, pwd, export, unset, env, and exit
  • Support for an initially empty environment through env -i

Command lifecycle

flowchart LR
    Input[Readline input] --> Lexer[Lexer and tokens]
    Lexer --> Parser[Parser and command tree]
    Parser --> Expand[Quotes and expansion]
    Expand --> Execute[Execution plan]
    Execute --> Builtin[Parent-process builtin]
    Execute --> Children[Forks and pipelines]
    Children --> Redirections[Redirections and heredocs]
    Redirections --> Execve[Executable resolution and execve]
Loading

The parser first turns the input into tokens, validates their ordering, and separates commands from redirections. The resulting structures are then expanded and converted into the representation consumed by the executor.

Standalone builtins that modify shell state run in the parent process. External commands and pipeline stages run in child processes with their file descriptors configured before execve. The shell records the final child status so it can be used by $? and subsequent commands.

My contribution

My primary responsibility was the execution layer and builtins, together with their integration with the parser.

  • Implemented process creation, pipes, descriptor management, and child waiting
  • Built input/output redirections and heredoc execution
  • Implemented shell builtins and parent-process state updates
  • Resolved executable paths and reproduced shell-style execution errors
  • Managed exit statuses across builtins, external commands, and signals
  • Improved environment handling, expansion edge cases, and empty-environment use
  • Participated in integration, debugging, memory cleanup, and final delivery

The parsing and execution sides were developed as complementary parts of the same two-person project.

Build and run

Requirements

  • A Unix-like operating system
  • A C compiler and make
  • GNU Readline development headers

On Debian or Ubuntu:

sudo apt install build-essential libreadline-dev

On Fedora:

sudo dnf install gcc make readline-devel

Build and start the shell:

git clone https://github.com/C1STA/minishell.git
cd minishell
make
./minishell

Example session:

minishell$ export PROJECT=minishell
minishell$ echo "building $PROJECT" | wc -w
2
minishell$ printf "alpha\nbeta\n" > output.txt
minishell$ cat < output.txt
alpha
beta
minishell$ echo $?
0

Available maintenance targets:

make clean
make fclean
make re
make norm

For a local memory check with Valgrind:

valgrind --leak-check=full --track-origins=yes \
  --suppressions=readline.supp --track-fds=yes ./minishell

Project structure

.
|-- inc/                 Shared parser and executor interfaces
|-- src/
|   |-- parsing/lexer/   Tokenization and quote-aware input scanning
|   |-- parsing/parser/  Syntax checks, expansion, and command structures
|   |-- exe/             Processes, pipes, redirections, and builtins
|   |-- builtin/         Environment-list operations
|   |-- signals/         Interactive signal behavior
|   `-- ft_free/         Centralized structure cleanup
|-- lib/libft/           Project utility library
|-- readline.supp        Valgrind suppressions for Readline
`-- Makefile

Validation

  • Compiled with -Wall -Wextra -Werror
  • Automated Linux build and smoke test through GitHub Actions
  • Behavioral checks covering quoting, expansion, redirections, pipelines, builtins, exit statuses, and signal behavior
  • Valgrind suppression file included for isolating project-owned allocations

Minishell intentionally implements a focused subset of Bash. Features outside that scope, such as command lists with && or ||, globbing, and job control, are not included.

About

A Bash-inspired shell in C with parsing, pipelines, redirections, expansion, builtins, and signal handling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages