Created: July 29, 2022 3:05 PM Tags: C Language, School
Minishell is a 42-school project that aims to introduce as the world of shells by recoding out mini bash, a program that can parse, execute, and launch executables along with some built-in commands.
readline, rl_clear_history, rl_on_new_line, rl_replace_line, rl_redisplay, add_history, printf, malloc, free, write, access, open, read, close, fork, waitpid, signal, kill, exit, getcwd, chdir, execve, dup2, pipe, perror.
- input: Readline output
- output: tokenized linked list
- the objective of this step is to split the readline output using tokens (defined macros)
- used tokens: WORD, REDIRECTION, PIPE, AND, SEMI, PARENTHESIS
- input: tokenized linked list
- output:
- in case of no syntax error: same tokenized linked list.
- in case of a syntax error: printed error type.
- the objective of this step is to check all possible command syntax errors (if you have a doubt about an error take bash as a reference).
- input: tokenized linked list
- output: commands linked list
- we can split this step into 2 sub-steps
- handling redirections (input, output, append, heredoc).
- add command to the linked list with their file descriptors (in and out).
- input: commands linked list
- if everything went okay in the past steps we have 2 different cases to communicate between the commands (processes):
- if there are
$N$ commands we initialize$N-1$ pipes to communicate between the processes we create. - In another case, if there’s some kind of redirection, it takes the priority
- if there are
- the only step left is to verify if the command is available or not there are two ways to handle it depending on the command itself
- relative path
- absolute path
- in this part, the commands are ready to be executed
- shell maintains an environment that includes a set of variables defined by a name, a user initialization, and system initialization.
- sources that can help you like us:
- Tokenization is a way of separating a sentence into smaller units called tokens,
- Sources that can help you like us:
- It analyses the syntactical structure and checks if the given input is in the correct syntax of the programming language or not.
- built-in commands it's just built into the shell itself, while an external command is an external file launched by the shell, the external file may be a binary or some kind of shell script if you use a different version of the shell the builtin while always be available when external could not be installed or need a different supported version.
- The function
readline()
prints a prompt and then reads and returns a single line of text from the user. If the prompt isNULL
or the empty string, no prompt is displayed. The linereadline
returns are allocated withmalloc()
; the caller shouldfree()
the line when it has finished with it.- Sources that can help you like us:
- there is no such thing as a perfect project, bash is a large project that was updated years after year for 43 years, for newbies like us who have never coded something like this, I'm very proud we did complete this project in 2 months, in the end, the only thing who gonna develop is your knowledge.
~rsaf