|Fabien Stadelwieser e1eed84ab9||4 months ago|
|inc||1 year ago|
|lib/libft||1 year ago|
|src||1 year ago|
|.function_whitelist.txt||1 year ago|
|.gitignore||1 year ago|
|Makefile||1 year ago|
|README.md||4 months ago|
|author||1 year ago|
|bonuslist.txt||1 year 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://email@example.com:42084/Fabien/minishell.git cd minishell make
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
Student project for School 42.
Realized by myself in about a week.
Final Grade: 120/125