Skip to content

AdriaPriego/MiniShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Repo stars GitHub top language GitHub code size in bytes GitHub last commit (by committer) MacOS compatibility

Minishell, recreating bash. (42 school project)

The aim of this project is to create a shell using bash (bourne-again shell) as reference.

About The Project

minishell_screenshot

Minishell is a Unix shell really similar to bash but with some reduced functionalities. The project is written from scratch in C. Some of the functionalities are:

  • Displays current directory when waiting for a new command.

  • Working history of commands.

  • Searches and launches the right executable (based on the PATH variable or using a relative or an absolute path).

  • Variable expansion of environment variables, tilde characater '~' and $?.

  • Single and double quotes as bash would, single quotes prevent the shell from interpreting the metacharacters in the quoted sequence.

  • Redirections:

    • '<' Redirects input.
    • '>' Redirects output.
    • '<<' + DELIMITER, reads the input until a line containing the delimiter is seen. It doesn’t update the history.
    • '>>' Redirects output in append mode.
  • Works with pipes '|'. The output of each command in the pipeline is connected to the input of the next command via a pipe.

  • $? is updated with the exit code of the last executed command in the pipe.

  • Handles signals ctrl-C, ctrl-D and ctrl-\ which behave like in bash.

  • To finish, the following built-in commands were implemented from scratch:

    • echo with option -n
    • cd with only a relative or absolute path
    • pwd with no options
    • export with no options
    • unset with no options
    • env with no options or arguments
    • exit

Note

This project doesn't handle the following functionalities:

  • STDERR redirection like '2>' or STDERR + STDOUT redirection like '&>'.
  • Unclosed quotes. If quotes are left unclosed minishell will interpret there is a closing quote at the end of the command.
  • Commands ending with a pipe character '|'. Minishell will throw a syntax error on that case.
  • Logical operators like '&&' and '||'.
  • Special characters like '/' and ';'.
  • Wildcards '*'.

Getting Started

In order to run the program first clone the repository:

git clone git@github.com:adriapriego/minishell.git

Open the folder:

cd minishell/

Compile the program:

make

Run the program:

./minishell

Note

Additionally the executable could be moved to a directory in the $PATH to make it work from anywhere in the computer typing 'minishell', like bash.

Authors

This project is written by @ferri17 and me as part of 42 School core curriculum. I was mainly focused on the focused on the built-ins, expansor, and signals, while Ferran focused on the lexer(tokenizer), parser, and executor.