This is a rebuild of bash. This program can be separated into 3 Parts:
Takes the input in form of a string and cuts it into words and signs.
Takes the strings from the Lexer and gives them a meaning. In other words creates tokens.
String | Token |
---|---|
> | redirection |
cat | command |
-l | argument |
| | pipe |
A pipe signals the end of a command line and the beginning of a new one. Every command line is being stored in an array. Each command line consists of:
- Command
- Arguments
- StdIn
- StdOut
The executer will go through the array and executes each command one by one while also checking for possible redirections.
Default for Input and Output is StdIn and StdOut. For each pipe-token, the StdOut gets geplaced by a file descriptor (fd). This fd[0] will be connected to another fd[1]. This is a pipe. fd[1] is the input of the next command line. > and < tokens are redirections pointing to a custom file. A fd will be created for the file and Input or Output redirected to this fd.
Each execution of a command line runs in a different child process. This means everything is being executed at the same time.
Et voila! Try it if you dare!
- clone this repository
cd minishell
make
./minishell