As beautiful as a shell
This program was created by Aiko Achappui and Tal Kashi as part of the 42 school curriculum. Minishell is a minimal version of a shell that supports both Linux and macOS.
For parsing and execution, we utilized an Abstract Syntax Tree (AST). The AST processes commands recursively until it reaches the simplest level(smallest leaves), known as a "simple command," such as
cat file.c
-
Logical Operators: Supports logical operators such as && (AND) and || (OR).
-
Allows the use of multiple pipes (|) for chaining commands.
-
Supports parenthesis () to create subshells for grouped command execution.
-
Redirections:
- Input redirection with <.
- Output redirection with >.
- Heredoc redirection with <<.
- Append redirection with >>.
-
Environment Variables: Use $ to access and manipulate environment variables within commands.
-
Wildcard Support: Supports the use of * wildcards to match patterns within the current directory.( Examples include .* and *c**a, without using relative paths.)
-
Quoting Mechanisms: Single quotes (') to treat enclosed text as a literal string.
-
Double quotes (") to cancel metadata charachters.
-
Builtin Functions: Implements several built-in shell functions:
- echo: Print arguments to the standard output.
- pwd: Print the current working directory.
- env: Display the environment variables.
- cd: Change the current directory.
- export: Set environment variables.
- unset: Unset environment variables.
- exit: Exit the shell.
a short explanation of the process the line goes through :
- tokenizer: returning a pointer to a head of a linked list. a basic "split" function that defines the type of the token. its skips whitespaces and stops when encountering one of the following : "||" "&&" "|" "(" ")".
- syntax analyzer checks before running the programm that the order of the operators makes sences, (refering from bash) and relatively to the position of the operator inside the line.
- tree maker : looks for the righest operator he finds ( || or && ) and with each one it encounter, it creates another 2 childs. than recursively calling the function, searching for the pipes and for the parenthesis (for parenthesis it forks once than a parenthesis have only one child), than looking for the smallest unites of command lines. a command line includes the redirections. (include here the template)
In order to run minishell, first clone the project using
git clone git@github.com:Talkashi1111/mini_shell.git
than cd to the repository and run make command to build the Minishell program:
- Regular build:
make
- You can also test for memory leaks using your own arguments or the default ones by running:
make leak
The project's Makefile automatically configures the memory leak detection tool based on the operating system:
- Linux: By default, the tool is set to valgrind.
- Mac: The tool is set to leaks with the --atexit option.
- A debugging mode is available to visualize the command tree structure.
- Enable debugging by running
DEBUG=1 make re
during installation.
DEBUG=1 make re
- Run the Program:
./minishell
Thank you for looking through our Minishell! If you have any questions or issues, or ideas to improve it, don't hesitate to contact me ( or Aiko).