Skip to content

Orpheus-3145/minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minishell

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.

Overview

See the subject of the project for the specific guidelines, but substantially minishell behaves as Bash; here are listed the main semplifications.

1. Sintax

  • Unclosed quotes are treated as sintax-errors;
  • characters '\' and ';' are not considered meta-characters and have no consequence;
  • operations && and || are not implemented.

2. Signals

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.

3. Builtins

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).

4. Redirections

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.

Approach

The whole workload was splitted into two main parts:

  1. 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, ... .
  2. 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.

Code

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().

Compiling and running

The project relies on a submodule (Libft) for low level C operations.

  1. make creates the executable;
  2. make run calls make and runs the executable;
  3. make clean removes object files;
  4. make fclean calls make clean and removes the executable;
  5. make re calls make fclean and then make;

Structure

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

References

About

Implementation of the Bash shell

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published