The idea of the project is to create a new shell, able to execute commands, manage environment variables, ... This shell is directly inspired to the Bash shell and behaves like it as much as possibile, specifically the one used on UNIX (OS X).
Minishell was a project developed by my team-partner ys_zm ( <--- many thanks for the cooperation!) and me.
See the subject of the project for the specific guidelines, but substantially minishell behaves as Bash; here are listed the main semplifications.
- Unclosed quotes are treated as sintax-errors;
- characters '\' and ';' are not considered meta-characters and have no consequence;
- operations && and || are not implemented.
The signals interally implemented are:
- SIG_INT (CTRL C) -- interrupts the running command prints an empty prompt;
- SIG_QUIT (CTRL \) -- default behaviour set as ignore
- EOF (CTRL D) -- exits the shell.
Some commands was directly implemented in the shell at C level (a.k.a. builtins), the others are executed as usual looking for the executable inside the $PATH variable. The builtins are: (only the options inside the parenthesis are admitted)
- echo (only 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 (no options).
The IO redirections are treated as follows:
- < -- single input redirection ;
- > -- single output redirection ;
- << -- double input redirection or here_doc (multiline input redirection) mode;
- >> -- double output redirection or append mode.
The whole workload was splitted into two main parts:
- parsing -> (in which the undersigned was involved) it consists of refining the input throught the following steps:
- parser: a string is read for the input prompt (input operation realy on readline C-library) and also the sintax is checked;
- expander: variable expansion (variables inside single quotes are not expanded);
- tokenizer: the input is splitted into single commands (if there are pipes) and then into single tokens;
- lexer: the tokens are classified into categories, such as main command, parameter, redirection, ... .
- execution -> that encloses the following areas:
- executor: that is to say the real execution, i.e. from the collected tokens the correspondent command is run on a separate process;
- builtins: implementation of the C functions of the builtins previously listed;
- env variables: handling of the environment variables;
- cleaning: destructors and error management.
The project is written in C, according to the Norm, and it is compiled with the flags:
- -Werror
- -Wextra
- -Wall
- -fsanitize=address
N.B. sometimes (inside Linux environment especially) the program might fail when exited, because of some leaks caused by the C function readline().
The project relies on a submodule (Libft) for low level C operations.
make
creates the executable;make run
callsmake
and runs the executable;make clean
removes object files;make fclean
callsmake clean
and removes the executable;make re
callsmake fclean
and thenmake
;
include/ <- header file
libft/ <- auxiliary submodule
objects/ <- object files
sources/ <- source C files
builtins/ <- builtins commands
checker/ <- checks to perform on the input sequence command
env/ <- handling of environment variables
error_handling/ <- errors and destructors
exec/ <- executor
here_doc/ <- here_doc handling
lexer/ <- tokenization
main/ <- main function and signal handling
parser/ <- input storing, checks and variable expansion
utils/ <- generic use functions
- 42 project: minishell
- By: Francesco Aru and ys_zm, francesco.aru25@gmail.com, intra42/slack nickname: @faru, Codam, Amsterdam