This project has been created as part of the 42 curriculum by lmouta-g & agoram.
minishell — minishellyy 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,envandexit. - 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.
The project links against readline, so the development package must be
installed:
sudo apt install libreadline-devmakeUseful rules:
make clean # remove object files
make fclean # remove objects and the binary
make re # rebuild from scratchThe project is compiled with -Wall -Wextra -Werror.
./minishellThen type commands as you would in bash:
minishellyy > echo "hello $USER" | cat
minishellyy > ls -la | grep .c | wc -l
minishellyy > cat << EOF > out.txtinc/ 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
manpages:readline,bash,execve,pipe,dup2,wait,signal,sigaction,termios.- GNU Readline documentation
- The
bashreference 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 :)