In this project, students are tasked with building a program that executes in a loop*, prompting the user for a command (or sequence of commands**), interpreting the inserted input and then executing the command, finally returning the prompt back to the user, until it is terminated by the user.
This minishell is able to run any commands that can be found in the $PATH
variable or otherwise in a specified path; redirect input and outputs with redirection operators, as well as some built-in functionalities, and also supports the wildcard character *
.
*Commonly referred to as REPL - Read, Evaluate and Print Loop. Learn more about the REPL studying this diagram.
**Also know as
pipelines
, that is, a sequence of terminal commands separated by the pipe character|
.
Minishell is a miniature shell program based on Bash. Minishell supports:
- Prompt display
- Command history (up and down arrows)
- System executables available from the environment (
ls
,cat
,grep
, etc.) - Local executables (
./minishell
) - Builtin commands :
echo
(and option-n
)cd
(with only a relative or absolute path)pwd
(no options)export
(no options)unset
(no options)env
(no options or arguments)exit
(with exit number but no other options)
- Pipes
|
which redirect output from one command to input for the next - Redirections:
>
redirects output>>
redirects output in append mode<
redirects input<< DELIMITER
displays a new prompt, reads user input until reachingDELIMITER
, redirects user input to command input (does not update history)
- Environment variables (i.e.
$USER
or$VAR
) that expand to their values.$?
expands to the exit status of the most recently executed foreground pipeline.
- User keyboard signals:
ctrl-c
displays a new prompt line.ctrl-d
exits minishellctrl-\
does nothing
However, Minishell does not support \
, ;
, &&
, ||
, or wildcards.
🇺🇸 Articles in English about the concepts tackled in this project:
- Creating and Killing Child Processes in C
- Pipe: an Inter-Process Communication Method
- Sending and Intercepting a Signal in C
- Handling a File by its Descriptor in C
- Errno and Error Management in C
🇫🇷 Articles en français sur les concepts abordés dans ce projet :
- Créer et tuer des processus fils en C
- Pipe : une méthode de communication inter-processus
- Envoyer et intercepter un signal en C
- Manipuler un fichier à l’aide de son descripteur en C
- Errno et la gestion d’erreur en C
Other useful links:
- Bash reference manual
- Introduction to Systems Programming: a Hands-on Approach, Chapter 5. Writing Your Own Shell
- Stephen Brennan's Tutorial - Write a Shell in C
- The Open Group Base Specifications, Shell Command Language
- A Guide to Unix Shell Quoting
- Austin Tripp's Quick Tutorial on Bash Quotes
$> git clone https://github.com/RogerioLS/Minishell-42sp
$> cd Minishell-42sp
$> make
$> ./minishell
If you want to exit the minishell, simply type in the command exit
or press ctrl+D
. There ya go!
Note
Because of 42 School norm requirements:
- Each function can't have more than 25 lines of code.
- All variables are declared and aligned at the top of each function.
- Project should be created just with allowed functions otherwise it's cheating.