||10 months ago|
|inc||2 years ago|
|lib/libft||2 years ago|
|src||2 years ago|
|.function_whitelist.txt||2 years ago|
|.gitignore||2 years ago|
|Makefile||2 years ago|
|README.md||10 months ago|
|author||2 years ago|
|bonuslist.txt||2 years ago|
A simple posix shell.
./minishell $> # type you command here $> ls file1 file2 $> ls nofile $> echo $? 1 $> cd .. $> echo $TEST $> setenv $TEST value $> echo $TEST value $> exit
Compatible Linux and MacOS
git clone ssh://firstname.lastname@example.org:42084/Fabien/minishell.git cd minishell make
How it works
Normally almost each shell has a script is loaded from a file named :
It's not part of this project, and so are the arguments.
In this project the input is fairly simple. You use a function from another
project, the infamous
You need a solid
get_next_line, many bugs can come from a bad one
that have not been written with interactive input in mind.
So you loop over the input (fd -> 0 sometime called stdin).
And for each line you do a
strsplit on each line,
where you split on <space>.
The first "word" is the command for this project, the rest is the argument, you just keep them for later.
If the command have a '/' in it the path is checked, if correct you skip the next step.
Otherwise, you search in the env for a variable called
$> echo $PATH /bin:/usr/bin:/home/user/.bin
Then for each command search in each directory listed in $PATH.
/home/user/.binis not checked because
lshave already been found
When the executable has been found, a new process is created with
the command is run with its argument thanks to
execve and the main
process wait for its child to finish with
man fork man execve man wait
Some command cannot have the desired result in a child process.
One example of this is exiting the shell or modifying the env. Each of those would only affect the child and then return to the parent leaving nothing.
For those cases, shells have something called "builtins" that are not run in the main process.
In our case they are :
These are a builtin for the sake of the exercise, but don't need to be.
Builtin are checked before the command, so if you want to exec
you need to type
/usr/bin/env and simply
env for the builtin.
man env give you informations about the executable whereas
help env, give you info about the builtins. (No
help in our case)
Don't forget to store the return value in
$? and return this when the
- Non-interactive input (ei: pipe as input)
- Simple and double quotes [' and "]
- Backslash [\]
- Multiline input
- Signal management (<Ctrl + C> and <Ctrl + \>)
- Proper signal message and "core dumped"
- Run on Linux
- tcsh compatible on the feature-set
Student project for School 42.
Realized by myself in about a week.
Final Grade: 120/125