Skip to content
AyoubkrifPublic

About

Minishell 42 project

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

This project has been created as part of the 42 curriculum by aykrifa, cbordeau.

Minishell

Demo


Description

Minishell is a minimal Unix shell written in C, built as part of the 42 school curriculum. The goal is to reproduce the core behavior of Bash — from command parsing and execution to redirections, pipes, signals, and built-in commands.

The shell is built around an Abstract Syntax Tree (AST) — each command line is parsed into a tree of nodes (EXEC, PIPE, REDIR, LINE) that is then walked recursively at execution time. This architecture is directly inspired by the shell from the xv6 RISC-V teaching kernel by MIT, extended with full Bash quoting rules, environment variable expansion, here-doc, wildcards, and logical operators.


Features

Core

  • Interactive prompt with command history (via GNU Readline)
  • Command lookup via PATH, relative path, or absolute path
  • Single global variable for signal number only (Norm-compliant)

Quoting

  • 'single quotes' — no interpretation of any metacharacter
  • "double quotes" — metacharacters suppressed except $

Redirections

Operator Behavior
< Redirect stdin from file
> Redirect stdout to file (truncate)
>> Redirect stdout to file (append)
<< Here-doc — read stdin until delimiter

Pipes & Logical Operators (bonus)

Operator Behavior
| Pipe — connects stdout of left to stdin of right
&& Execute right only if left succeeds
|| Execute right only if left fails
( ) Group commands, control evaluation priority

Expansion

  • $VAR — expand environment variable
  • $? — expand exit status of last foreground pipeline
  • * — wildcard glob for current working directory (bonus)

Signals

Signal Interactive behavior
Ctrl-C Display new prompt on a new line
Ctrl-D Exit the shell
Ctrl-\ Does nothing

Built-in Commands

Command Description
echo [-n] Print arguments to stdout, -n suppresses trailing newline
cd <path> Change working directory (relative or absolute)
pwd Print current working directory
export [VAR=val] Set or display environment variables
unset <VAR> Remove an environment variable
env Print all environment variables
exit [n] Exit the shell with optional status code

Instructions

Requirements

  • cc (GCC or Clang)
  • GNU Readline library (libreadline-dev on Debian/Ubuntu)
  • make

Compilation

make

This compiles libft then the shell. The binary is minishell.

Running

./minishell

Makefile rules

Rule Effect
make / make all Build the project
make clean Remove object files
make fclean Remove object files and binary
make re fclean + all
make bonus Build with bonus features

Resources

References

About

Minishell 42 project

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages