42 project, recoding our own little bash. A program capable of parsing a prompt and launching executables with arguments, along with a few built-in functions.
This project is about creating a simple shell. Yes, your own little bash.
You will learn a lot about processes and file descriptors.
Version: 6
You can read the subject: minishell.en.pdf
The existence of shells is linked to the very existence of IT. At the time, all developers agreed that communicating with a computer using aligned 1/0 switches was seriously irritating. It was only logical that they came up with the idea of creating a software to communicate with a computer using interactive lines of commands in a language somewhat close to the human language. Thanks to Minishell, you’ll be able to travel through time and come back to problems people faced when Windows didn’t exist.
Program name | minishell |
---|---|
Turn in files | Makefile, *.h, *.c |
Makefile | NAME, all, clean, fclean, re |
Arguments | |
External functs. | • readline, rl_clear_history, rl_on_new_line • rl_replace_line, rl_redisplay, add_history • printf, malloc, free, write, access, open, read • close, fork, wait, waitpid, wait3, wait4, signal • sigaction, sigemptyset, sigaddset, kill, exit • getcwd, chdir, stat, lstat, fstat, unlink, execve • dup, dup2, pipe, opendir, readdir, closedir • strerror, perror, isatty, ttyname, ttyslot, ioctl • getenv, tcsetattr, tcgetattr, tgetent, tgetflag • tgetnum, tgetstr, tgoto, tputs |
Libft authorized | Yes |
Description | Write a shell |
Your shell should:
-
Display a prompt when waiting for a new command.
-
Have a working history.
-
Search and launch the right executable (based on the PATH variable or using a relative or an absolute path).
-
Not use more than one global variable. Think about it. You will have to explain its purpose.
-
Not interpret unclosed quotes or special characters which are not required by the subject such as \ (backslash) or ; (semicolon).
-
Handle ’ (single quote) which should prevent the shell from interpreting the metacharacters in the quoted sequence.
-
Handle " (double quote) which should prevent the shell from interpreting the metacharacters in the quoted sequence except for $ (dollar sign).
-
Implement redirections: ◦ < should redirect input. ◦ > should redirect output. ◦ << should be given a delimiter, then read the input until a line containing the delimiter is seen. However, it doesn’t have to update the history! ◦ >> should redirect output in append mode.
-
Implement pipes (| character). The output of each command in the pipeline is connected to the input of the next command via a pipe.
-
Handle environment variables ($ followed by a sequence of characters) which should expand to their values.
-
Handle $? which should expand to the exit status of the most recently executed foreground pipeline.
-
Handle ctrl-C, ctrl-D and ctrl-\ which should behave like in bash.
-
In interactive mode: ◦ ctrl-C displays a new prompt on a new line. ◦ ctrl-D exits the shell. ◦ ctrl-\ does nothing.
-
Your shell must implement the following builtins: ◦ echo with option -n ◦ cd with only a relative or absolute path ◦ pwd with no options ◦ export with no options ◦ unset with no options ◦ env with no options or arguments ◦ exit with no options The readline() function can cause memory leaks. You don’t have to fix them. But that doesn’t mean your own code, yes the code you wrote, can have memory leaks.
You should limit yourself to the subject description. Anything that is not asked is not required.
If you have any doubt about a requirement, take __bash__ as a reference.
Your program has to implement:
- && and || with parenthesis for priorities.
Just like &&, || is a bash control operator:
&& means execute the statement which follows only if the preceding statement executed successfully (returned exit code zero).
|| means execute the statement which follows only if the preceding statement failed (returned a non-zero exit code).
- Wildcards * should work for the current working directory.
The bonus part will only be assessed if the mandatory part is PERFECT.
Perfect means the mandatory part has been integrally done and works without malfunctioning.
If you have not passed ALL the mandatory requirements, your bonus part will not be evaluated at all.