Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minishell

C 42 Norm Flags

This project has been created as part of the 42 curriculum by lmouta-g & agoram.


Description

minishellminishellyy at the prompt — is a simplified reimplementation of a Unix shell, written in C. It reads command lines from an interactive prompt, interprets them, and executes them the way bash does for the mandatory scope of the subject.

It supports:

  • A prompt with a working history (readline).
  • Running executables found through PATH, or via a relative or absolute path.
  • Single quotes ' (no interpretation) and double quotes " (interpretation of $ only).
  • Environment variable expansion ($VAR) and $? (exit status of the last foreground pipeline).
  • Redirections: <, >, >> and here-documents <<.
  • Pipelines (|) of arbitrary length.
  • The built-ins echo (with -n), cd, pwd, export, unset, env and exit.
  • Signal handling in interactive mode (ctrl-C, ctrl-D, ctrl-\) matching bash's behaviour.

A single global variable is used, and only to store the number of a received signal, as required by the subject.


Instructions

Requirements

The project links against readline, so the development package must be installed:

sudo apt install libreadline-dev

Compilation

make

Useful rules:

make clean   # remove object files
make fclean  # remove objects and the binary
make re      # rebuild from scratch

The project is compiled with -Wall -Wextra -Werror.

Usage

./minishell

Then type commands as you would in bash:

minishellyy > echo "hello $USER" | cat
minishellyy > ls -la | grep .c | wc -l
minishellyy > cat << EOF > out.txt

Structure

inc/         the project header (structs, macros, prototypes)
libs/        the libft (helpers and the arena allocator)
src/lexer    lexes the input line into tokens
src/parser   parses the tokens into commands and redirections
src/expander expands variables and removes quotes
src/executor executes commands, pipes, redirections and heredocs
src/builtin  the built-in commands
src/init     initializes the environment
src/signals  handles the signals
src/utils    small helper functions

Resources

  • man pages: readline, bash, execve, pipe, dup2, wait, signal, sigaction, termios.
  • GNU Readline documentation
  • The bash reference manual, used as the behavioural reference whenever the subject was ambiguous.
  • libft — this project relies on my own libft.
  • Thanks to Agoram for the arena allocator idea — it is basically what powers the whole memory management of this minishell :)

About

A simplified Unix shell written in C: pipelines, redirections, heredocs, quoting, expansions and built-ins. 42 project.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages